-
[Python tutorial] 3. Data types코딩/Python 2022. 12. 21. 17:10728x90
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
Collections (Arrays)
- List: ordered, changeable, Allows duplicate members
- Tuple: ordered, unchangeable, Allows duplicate members
- Set: unordered, unchangeable(possible to remove/add), unindexed, No duplicate members
- Dictionary: ordered, changeable, No duplicate members
Getting the Data Type: type()
x = 5 print(type(x)) # <class 'int'>
Setting the Data Type
myStr = "Hello World" # str myInt = 20 # int myFloat = 20.5 # flaot myComplex = 1j # Complex myList = ["apple", "banana", "cherry"] # list myTuple = ("apple", "banana", "cherry") # tuple myRange = range(6) # range myDict = {"name" : "John", "age" : 36} # dict mySet = {"apple", "banana", "cherry"} # set myFrozenset = frozenset({"apple", "banana", "cherry"}) # frozenset() myBool = True # bool myBytes = b"Hello" # bytes myBytearray = bytearray(5) # bytearray() myMemoryview = memoryview(bytes(5)) # memoryview myNone = None # NoneType
Setting the Specific Data Type
myStr = str("Hello World") myInt = int(20) myFloat = float(20.5) myComplex = complex(1j) # complex myList = list(("apple", "banana", "cherry")) # list, (()) myTuple = tuple(("apple", "banana", "cherry")) # tuple, (()) myRange = range(6) # range myDict = dict(name="John", age=36) # dict mySet = set(("apple", "banana", "cherry")) # set myBool = bool(5) # bool myBytes = bytes(5) # bytes
728x90'코딩 > Python' 카테고리의 다른 글
[Python tutorial] 5. Data type - Strings (1) 2022.12.21 [Python tutorial] 4. Data type - Numbers (0) 2022.12.21 [Python tutorial] 2. Basic, Variables, Module, User input (0) 2022.12.21 [Python tutorial] 1. Introduction (0) 2022.12.21 [Python] 모듈 Module과 __main__ (0) 2022.12.20