본문 바로가기

Python 배우기50

boolean_order.py name = "John" age = 17 print(name == "John" or not age > 17) print(name == "John" or not age > 17) print(name == "Ellis" or not (name == "John" and age == 17)) # Check if "name" is "Ellis" or it's not true that "name" equal "John" and he is 17 years old at the same time. 산출물 (Output) True True False * Boolean operators are not evaluated from left to right. There's an order of operations for bool.. 2016. 3. 8.
boolean_operators.py name = "John" age = 17 print(name == "John" or age == 17) # checks that either name equals to "John" OR age equals to 17 print(name == "John" and age != 23) # Check if "name" is equal to "John" and he is not 23 years old. 산출물 (Output)TrueTrue * Boolean operators compare statements and return results in boolean values. The boolean operator "and" returns True when the expressions on both sides of .. 2016. 3. 8.
in_keyword.py grocery_list = ["fish", "tomato", 'apples'] # create new list print("tomato" in grocery_list) # check that grocery_list contains "tomato" item grocery_dict = {"fish": 1, "tomato": 6, 'apples': 3} # create new dictionary print('fish' in grocery_dict) # Check if grocery_dict keys contain "fish". 산출물 (Output) TrueTrue * "in" keyword는 list 또는 dictionary에 특정 item이 포함되어 있는지 여부를 체크하는데 사용됩니다. strings에 한.. 2016. 3. 8.
dict_key_value.py phone_book = {"John": 123, "Jane": 234, "Jerard": 345} # 새 dictionary 만들기 print(phone_book) # dictionary에 새로 item 추가하기 phone_book["Jill"] = 456 print(phone_book) print(phone_book.keys()) print(phone_book.values()) # "phone_book"에서 모든 값을 프린트 하기. 산출물 (Output){'Jerard': 345, 'Jane': 234, 'John': 123} {'Jill': 456, 'Jerard': 345, 'Jane': 234, 'John': 123} dict_keys(['Jill', 'Jerard', 'Jane', 'John'].. 2016. 3. 7.
dicts.py # create new dictionary. phone_book = {"John": 123, "Jane": 234, "Jerard": 345} # "John", "Jane" and "Jerard" are keys and numbers are values print(phone_book) # Add new item to the dictionary phone_book["Jill"] = 345 print(phone_book) # Remove key-value pair from phone_book del phone_book['John'] print(phone_book['Jane']) # Print Jane's phone number from "phone_book". 산출물 (Output) {'Jane': 234,.. 2016. 3. 7.
tuples.py alphabet = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z') print(len(alphabet)) 산출물 (Output) 26 * Tuples는 lists와 거의 동일합니다. tuples와 lists간의 유일한 중요한 차이점은 tuples는 변경될 수 없다는 점입니다: tuple로부터 엘리먼트를 추가, 변경 또는 삭제할 수 없습니다. Tuples는 괄호로 둘러싸인 쉽표 운영자로 construct 됩니다(예, (a, b, c)). 단일 item tuple은 (d,)와 같이 쉼표가 뒤에 와야 합니다. Print the.. 2016. 3. 7.