Built-in 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
None Type:
NoneType
Getting the Data Type
type() செயல்பாட்டைப் பயன்படுத்தி எந்த பொருளின் தரவு வகையையும் பெறலாம்:
Example
x = 5
print(type(x))
Setting the Data Type
பைத்தானில், நீங்கள் ஒரு மதிப்பை ஒரு மாறிக்கு ஒதுக்கும் போது தரவு வகை அமைக்கப்படுகிறது:
| Example | Data Type |
|---|---|
| x = "Hello World" | str |
| x = 20 | int |
| x = 20.5 | float |
| x = 1j | complex |
| x = ["apple", "banana", "cherry"] | list |
| x = ("apple", "banana", "cherry") | tuple |
| x = range(6) | range |
| x = {"name" : "John", "age" : 36} | 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 = None | NoneType |
Setting the Specific Data Type
நீங்கள் தரவு வகையைக் குறிப்பிட விரும்பினால், பின்வரும் கட்டமைப்பாளர் செயல்பாடுகளைப் பயன்படுத்தலாம்:
| Example | Data Type |
|---|---|
| x = str("Hello World") | str |
| x = int(20) | int |
| x = float(20.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="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 |