SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Arguments
Information can be passed to the function as arguments.
Specify arguments in parentheses after the function name. You can add as many arguments as you need, just separate
them with commas.
def
welcome
(name, msg):
"""This is a welcome function for
the person with the provided message"""
(
"Hello"
, name
+
', '
+
msg)
welcome(
"Lily"
,
"Welcome to China!"
)
>>> %Run -c $EDITOR_CONTENT
Hello Lily, Welcome to China!
Number of Arguments
By default, a function must be called with the correct number of arguments. Meaning that if your function expects 2
parameters, you have to call the function with 2 arguments, not more, and not less.
def
welcome
(name, msg):
"""This is a welcome function for
the person with the provided message"""
(
"Hello"
, name
+
', '
+
msg)
welcome(
"Lily"
,
"Welcome to China!"
)
Herethe function welcome() has 2 parameters.
Since we called this function with two arguments, the function runs smoothly without any errors.
If it is called with a different number of arguments, the interpreter will display an error message.
The following is the call to this function, which contains one and one no arguments and their respective error messages.
welcome("Lily")Only one argument
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
TypeError: function takes 2 positional arguments but 1 were given
welcome()No arguments
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
TypeError: function takes 2 positional arguments but 0 were given
3.5. MicroPython Basic Syntax
123
Содержание Thales Kit
Страница 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Страница 10: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 6 Chapter 1 Introduction to Raspberry Pi Pico ...
Страница 12: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 8 Chapter 2 What is Included in This Kit ...
Страница 13: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 1 Components List 2 1 Components List 9 ...
Страница 42: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 38 Chapter 2 What is Included in This Kit ...
Страница 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Страница 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...