EasyManua.ls Logo

SunFounder ESP32 - Page 304

Default Icon
771 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder ESP32 Starter Kit
3.6.9 Data Types
Built-in Data Types
MicroPython has the following data types:
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
Getting the Data Type
You can get the data type of any object by using the type() function:
a = 6.8
print(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"]
print(type(x))
print(type(y))
print(type(z))
>>> %Run -c $EDITOR_CONTENT
<class 'str'>
<class 'int'>
<class 'list'>
>>>
298 Chapter 3. For MicroPython User

Table of Contents