Ma’lumot tipini belgilash
Ma’lumot tipini belgilash
Python’da ma’lumot tipi o‘zgaruvchiga qiymat berganingizda belgilanadi:
| Misol | Ma’lumot tipi | Sinab ko‘ring |
|---|---|---|
| x = "Hello World" | str | Sinab ko‘ring » |
| x = 20 | int | Sinab ko‘ring » |
| x = 20.5 | float | Sinab ko‘ring » |
| x = 1j | complex | Sinab ko‘ring » |
| x = ["apple", "banana", "cherry"] | list | Sinab ko‘ring » |
| x = ("apple", "banana", "cherry") | tuple | Sinab ko‘ring » |
| x = range(6) | range | Sinab ko‘ring » |
| x = {"name" : "John", "age" : 36} | dict | Sinab ko‘ring » |
| x = {"apple", "banana", "cherry"} | set | Sinab ko‘ring » |
| x = frozenset({"apple", "banana", "cherry"}) | frozenset | Sinab ko‘ring » |
| x = True | bool | Sinab ko‘ring » |
| x = b"Hello" | bytes | Sinab ko‘ring » |
| x = bytearray(5) | bytearray | Sinab ko‘ring » |
| x = memoryview(bytes(5)) | memoryview | Sinab ko‘ring » |
Muayyan ma’lumot tipini belgilash
Ma’lumot tipini aniq ko‘rsatmoqchi bo‘lsangiz, quyidagi konstruktor funksiyalaridan foydalanishingiz mumkin:
| Misol | Ma’lumot tipi | Sinab ko‘ring |
|---|---|---|
| x = str("Hello World") | str | Sinab ko‘ring » |
| x = int(20) | int | Sinab ko‘ring » |
| x = float(20.5) | float | Sinab ko‘ring » |
| x = complex(1j) | complex | Sinab ko‘ring » |
| x = list(("apple", "banana", "cherry")) | list | Sinab ko‘ring » |
| x = tuple(("apple", "banana", "cherry")) | tuple | Sinab ko‘ring » |
| x = range(6) | range | Sinab ko‘ring » |
| x = dict(name="John", age=36) | dict | Sinab ko‘ring » |
| x = set(("apple", "banana", "cherry")) | set | Sinab ko‘ring » |
| x = frozenset(("apple", "banana", "cherry")) | frozenset | Sinab ko‘ring » |
| x = bool(5) | bool | Sinab ko‘ring » |
| x = bytes(5) | bytes | Sinab ko‘ring » |
| x = bytearray(5) | bytearray | Sinab ko‘ring » |
| x = memoryview(bytes(5)) | memoryview | Sinab ko‘ring » |
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
