SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Getting the Data Type
You can get the data type of any object by using the
type()
function:
a
=
6.8
(
type
(a))
>>> %Run -c $EDITOR_CONTENT
<class 'float'>
Setting the Data Type
MicroPython does not need to set the data type specifically, it has been determined when you assign a value to the
variable.
x
=
"welcome"
y
=
45
z
=
[
"apple"
,
"banana"
,
"cherry"
]
(
type
(x))
(
type
(y))
(
type
(z))
>>> %Run -c $EDITOR_CONTENT
<class 'str'>
<class 'int'>
<class 'list'>
>>>
Setting the Specific Data Type
If you want to specify the data type, you can use the following constructor functions:
Example
Date Type
x = int(20)
int
x = float(20.5)
float
x = complex(1j)
complex
x = str(“Hello World”)
str
x = list((“apple”, “banana”, “cherry”))
list
x = tuple((“apple”, “banana”, “cherry”))
tuple
x = range(6)
range
x = dict(name=”John”, age=36)
dict
x = set((“apple”, “banana”, “cherry”))
set
x = frozenset((“apple”, “banana”, “cherry”))
frozenset
x = bool(5)
bool
x = bytes(5)
bytes
x = bytearray(5)
bytearray
x = memoryview(bytes(5))
memoryview
You can print some of them to see the result.
3.5. MicroPython Basic Syntax
127
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 ...