Interview question
What are Python's built-in data types? Python के built-in data types क्या हैं?
Answer
| Category | Types |
|---|---|
| Numeric | int, float, complex |
| Sequence | str, list, tuple, range |
| Mapping | dict |
| Set | set, frozenset |
| Boolean | bool |
| Binary | bytes, bytearray, memoryview |
| None type | NoneType |
print(type(5)) # <class 'int'>
print(type(5.0)) # <class 'float'>
print(type('text')) # <class 'str'>
print(type([1, 2])) # <class 'list'>
print(type((1, 2))) # <class 'tuple'>
print(type({'a': 1})) # <class 'dict'>
print(type({1, 2})) # <class 'set'>
print(type(True)) # <class 'bool'>
print(type(None)) # <class 'NoneType'>
# Checking types
x = 5
print(isinstance(x, int)) # True - preferred over type() == comparison| Category | Types |
|---|---|
| Numeric | int, float, complex |
| Sequence | str, list, tuple, range |
| Mapping | dict |
| Set | set, frozenset |
| Boolean | bool |
| None type | NoneType |
print(type(5)) # int
print(type('text')) # str
print(type([1, 2])) # list
print(type((1, 2))) # tuple
print(type({'a': 1})) # dict
print(type({1, 2})) # set
print(type(None)) # NoneType
x = 5
print(isinstance(x, int)) # True - preferred तरीकाWas this answer clear?