SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
3.5.5 If Else
Decision making is required when we want to execute a code only if a certain condition is satisfied.
if
if
test expression:
statement(s)
Here, the program evaluates the
test expression
and executes the
statement
only when the
test expression
is True.
If
test expression
is False, then
statement(s)
will not be executed.
In MicroPython, indentation means the body of the
if
statement. The body starts with an indentation and ends with
the first unindented line.
Python interprets non-zero values as “True”. None and 0 are interpreted as “False”.
if Statement Flowchart
Example
num
=
8
if
num
>
0
:
(num,
"is a positive number."
)
(
"End with this line"
)
>>> %Run -c $EDITOR_CONTENT
8 is a positive number.
End with this line
3.5. MicroPython Basic Syntax
113
Summary of Contents for Thales Kit
Page 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Page 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Page 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...