data type
-
[Python tutorial] 10. Data type - Dictionary코딩/Python 2022. 12. 21. 17:14
Dictionaries key:value pairs ordered changeable do not allow duplicates thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 # any data types } print(thisdict) print(thisdict["brand"]) {'brand': 'Ford', 'model': 'Mustang', 'year': 1964} Ford Access Dictionary Items x = thisdict["model"] print(x) # Mustang # get() x = thisdict.get("model") print(x) # Mustang # Get Keys: keys() x = thisd..
-
[Python tutorial] 9. Data type - Sets코딩/Python 2022. 12. 21. 17:14
Sets unordered**(unindexed) unchangeable(possible to remove & add) do not allow duplicate values thisset = {"apple", "banana", "cherry"} # any data types set1 = {"apple", "banana", "cherry"} set2 = {1, 5, 7, 9, 3} set3 = {True, False, False} set4 = {"abc", 34, True, 40, "male"} thisset = {"apple", "banana", "cherry", "apple"} print(thisset) # {'cherry', 'banana', 'apple'} Constructor: set(()) th..
-
[Python tutorial] 8. Data type - Tuple코딩/Python 2022. 12. 21. 17:13
Tuples ordered (indexed) unchangeable allow duplicate values thistuple = ("apple", "banana", "cherry", "apple", "cherry") # allow duplicate values # Data Types: any data types tuple1 = ("apple", "banana", "cherry") tuple2 = (1, 5, 7, 9, 3) tuple3 = (True, False, False) tuple4 = ("abc", 34, True, 40, "male") Create Tuple With One Item: (...,) thistuple = ("apple",) thistuple = ("apple") # NOT a t..
-
[Python tutorial] 7. Data type - List코딩/Python 2022. 12. 21. 17:12
List ordered changeable allow duplicate values Note Python에는 array가 없고 list를 대신 사용할 수 있다. 대량의 데이터는 NumPy를 사용한다. thislist = ["apple", "banana", "cherry", "apple", "cherry"] # allow duplicate values print(thislist) ['apple', 'banana', 'cherry', 'apple', 'cherry'] List Length: len() print(len(thislist)) # 5 Data Types - any data types list1 = ["apple", "banana", "cherry"] list2 = [1, 5, 7, 9, 3] li..
-
[Python tutorial] 6. Data type - Boolean코딩/Python 2022. 12. 21. 17:12
Booleans print(10 > 9) # True print(10 == 9) # False print(10 a: # False print("b is greater than a") else: print("b is not greater than a") # b is not greater than a Evaluate Values and Variables: bool() 어떤 값을 가지고 있으면 True 문자열이 비었다면 False 0이 아닌 숫자는 True 비어있지 않은 list, tuple, set, dict는 True True print(bool("Hello")) # True print(bool(15)) # True a = "" print(bo..
-
[Python tutorial] 5. Data type - Strings코딩/Python 2022. 12. 21. 17:11
Strings Assign String to a Variable a = "Hello" 파이썬 문자열은 변경 불가 a = 'Python' a[0] = 'J' # error Multiline Strings a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.""" b = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.''' # """string""", '..
-
[Python tutorial] 4. Data type - Numbers코딩/Python 2022. 12. 21. 17:11
Numbers int float complex Integer: int x = 1 y = 100 z = -300 Float x = 1.10 y = 1.0 z = -35.59 a = 35e3 # scientific numbers with an "e" b = 12E4 c = -87.7e100 Complex x = 3+5j y = 5j z = -5j Type Conversion int(), float(), complex() x = 1 # int y = 2.8 # float z = 1j # complex, 다른 타입으로 변환 불가 a = float(x) # 1.0 b = int(y) # 2 c = complex(x) # (1+0j) Random Number: random() Random module referen..
-
[Python tutorial] 3. Data types코딩/Python 2022. 12. 21. 17:10
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 ..