
SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
–
Case sensitive.
• Parameters (arguments) through which we pass values to a function. They are optional.
• The colon (:) marks the end of the function header.
• Optional docstring, used to describe the function of the function, we usually use triple quotes so that the doc-
string can be expanded to multiple lines.
• One or more valid Micropython statements that make up the function body. Statements must have the same
indentation level (usually 4 spaces).
• Each function needs at least one statement, but if for some reason there is a function that does not contain any
statement, please put in the pass statement to avoid errors.
• An optional
return
statement to return a value from the function.
Calling a Function
To call a function, add parentheses after the function name.
def
my_function
():
(
"Your first function"
)
my_function()
>>> %Run -c $EDITOR_CONTENT
Your first function
The return Statement
The return statement is used to exit a function and return to the place where it was called.
Syntax of return
return
[expression_list]
The statement can contain an expression that is evaluated and returns a value. If there is no expression in the statement,
or the
return
statement itself does not exist in the function, the function will return a
None
object.
def
my_function
():
(
"Your first function"
)
(my_function())
>>> %Run -c $EDITOR_CONTENT
Your first function
None
Here,
None
is the return value, because the
return
statement is not used.
122
Chapter 3. For MicroPython User
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 ...