نوع البيانات في Python
- الصفحة السابقة متغيرات Python
- الصفحة التالية Python أرقام
内置数据类型
在编程中,数据类型是一个重要的概念。
变量可以存储不同类型的数据,并且不同类型可以执行不同的操作。
在这些类别中,Python 默认拥有以下内置数据类型:
文本类型: | str |
数值类型: | int , float , complex |
序列类型: | list , tuple , range |
映射类型: | dict |
集合类型: | set , frozenset |
布尔类型: | bool |
二进制类型: | bytes , bytearray , memoryview |
设置数据类型
在 Python 中,当您为变量赋值时,会设置数据类型:
مثال | نوع البيانات | تجربة |
---|---|---|
x = "Hello World" | str | تجربة |
x = 29 | int | تجربة |
x = 29.5 | float | تجربة |
x = 1j | complex | تجربة |
x = ["apple", "banana", "cherry"] | list | تجربة |
x = ("apple", "banana", "cherry") | tuple | تجربة |
x = range(6) | range | تجربة |
x = {"name" : "Bill", "age" : 63} | dict | تجربة |
x = {"apple", "banana", "cherry"} | set | تجربة |
x = frozenset({"apple", "banana", "cherry"}) | frozenset | تجربة |
x = True | bool | تجربة |
x = b"Hello" | bytes | تجربة |
x = bytearray(5) | bytearray | تجربة |
x = memoryview(bytes(5)) | memoryview | تجربة |
تحديد نوع البيانات المحدد
إذا كنت ترغب في تحديد نوع البيانات، يمكنك استخدام بناءات التركيب التالية:
مثال | نوع البيانات | تجربة |
---|---|---|
x = str("Hello World") | str | تجربة |
x = int(29) | int | تجربة |
x = float(29.5) | float | تجربة |
x = complex(1j) | complex | تجربة |
x = list(("apple", "banana", "cherry")) | list | تجربة |
x = tuple(("apple", "banana", "cherry")) | tuple | تجربة |
x = range(6) | range | تجربة |
x = dict(name="Bill", 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 | تجربة |
- الصفحة السابقة متغيرات Python
- الصفحة التالية Python أرقام