1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
| print("---------If-else------------") # if-else myage=19 if(myage>=40): print ("아 한숨..") elif (myage >=20): print ("성인입니다") else: print("미성년입니다")
print("---------Function------------") # Function def greet(name): print(f'안녕 {name}아, 잘 지내냐?') print(f'안녕') greet("영희")
def greet2(name, age, location): print(f'{name} 는 {age} 이고 {location} 사는구나')
greet2('원형', '43', '분당') greet2(age=43, name='원형', location='분당')
print("---------Loop------------") # Loop x=0 y=0 while x <4: print("hello world in while", x,y); print(y) y=y+1 x=x+1
for a in range(3): print("hello world in range",a)
print("---------List------------") # List x = [] x = list() x= [1,2,3] print(x)
x= [[1,2],[3,4]] print(x)
x.append(4) x.append(5) print(x)
y=x.pop() print(x) print(y)
x[1]= 999 print(x)
x=["철수", "민수", "토마스", "민혜", "민수2"] print(x)
print("---------Tuple------------") # Tuple // immutable x = (1,2,3) print(x) #x[0] = 1 # error
print("---------Set------------") # Set (세트) // immutable, 검색 속도가 빠르다 x = set() x.add(1) x.add(2) print(x)
x= {1,2} print(x)
x= set(("1","2","3")) # x[0]=1 # error print(x)
x = set(("민수", "철수", "영희")) print(x)
x = [1,2,3,4,5,6] print(7 in x)
print("---------Dictionary------------") # Dictionary 사전, hash table # Key와 Value, Key 의 빠른 검색 x = {} x = dict() print(x)
x["이름"] ="미로" x["나이"] =20
print(x) print(x["이름"])
print ("이름" in x) print ("미로" in x) print ("성별" in x)
x = { 1,2,3} print (1 in x)
# Summary
# list vs tuple # list: mutable vs immutable # 1) list + tuple: ordered 순서가 정해져있다 - 내용물이 자료구조에 들어간 순서대루 # 2) 멤버쉽 검색이 느리다
# set vs dictionary # set: key value 가 필요 없고 key 만 필요 할때 # dict: key, value가 필요 할때 # 1) set + dictionary: unordered # 2) 검색이 빠르다
# Class and Heritance print("---------Class------------") class Person: def __init__(self,name): self.name=name def say_hello(self): print("안녕 나는 " + self.name)
a=Person("Mike") b=Person("Miro")
a.say_hello() b.say_hello()
print("------------Module, Package-----------") # Module(file), Package(folder) # import <PackageName><ModuleName> import msg.email # Module name = File name import msg.sms # from package import module from msg import sms
e= msg.email.Email() s= msg.sms.SMS()
e.send("mike", "miro", "hi") s.send("miro", "mike", "hi2") s.ping("010-123-1234")
print("------------Package call/ Geopy-----------") from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent="app") location = geolocator.geocode("Seoul, Korea") print(location.address) print((location.latitude, location.longitude)) print(location.raw) #Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ... #print((location.latitude, location.longitude)) #(40.7410861, -73.9896297241625) #print(location.raw) #{'place_id': '9167009604', 'type': 'attraction', ...}
|