Data Science Explorer

[Basic Grammar] Python Data Types 본문

Python

[Basic Grammar] Python Data Types

grace21110 2023. 10. 20. 12:22
반응형

Variables can store data of different types. 

 

Let's check out the data types that Python has.

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

 

When you want to know the data type of the variable, you can use type() function. 

Example 

x = 9.5
print(type(x))

 

  • Setting the Data Type 
Example  Data Type 
x = "Python is fun " str
x = 20 int
x = 99.9 float
x = 1j complex
x = ["Nike", "Adidas", "Puma"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
x = {"name" : "Grace", "age" : 28} 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