:
a = ['a', 'b', 'c']
for i, j in enumerate(a):
print(i+1, j)
:
(1) num = [1,6,99,3,28,8,9,12,56,17,284]
list(filter(lambda a : a % 2 == 0, num))
(2) num = [1,6,99,3,28,8,9,12,56,17,284]
def even(i):
if i % 2 == 0:
return i
print(list(filter(even, num)))
if__name__=="__main__:
의 용도는? ★면접질문!!!!:
try:
print(4/0)
except ZeroDivisionError as e:
print(e)
import sys
sys. .
:sys.path.append()
class Clothes:
def __init__(self,color,fit):
self.color = color
self.fit
= fit
def target(self,age,gender):
if age <= 5:
self.age = 'baby'
elif age <= 13:
self.age = 'kids'
elif age > 13 and gender == 'female':
self.age = 'adult'
self.gender = 'wemen'
else:
self.age = 'adult'
self.gender = 'men'
class Clothes2(Clothes):
def __init__(self, season, color, fit):
super().__init__(color, fit)
self.season = season
id_male =[] 남자의 주민번호 가져오기.
id_male = list(filter(lambda id : id[7] == '1',id))
id_male
https://colab.research.google.com/drive/1Ms5GnSwPWLGBONdypBHzsshEwf4qZF6P#scrollTo=bBcRBs4LdQzc
hex(15) -> 0xf
16진수 f, f -> 255
f:15, 15*16 + 15 = 255
def two_times(x):
return x*2
for i in zip([1,2,3],[4,5,6]):
print(i)
: (1, 4)
(2, 5)
(3, 6)
for i in zip([1,2,3],[4,5,6],["a","b","c"],["정","진","박"]):
print(i)
: (1, 4, 'a', '정')
(2, 5, 'b', '진')
(3, 6, 'c', '박')
pip install folium
pip install pandas
import folium
import pandas as pd
import os
os.getcwd() -> '/content'
-> 대학교만 보기
for name,lat,long in zip(df.대학교,df.위도,df.경도):
folium.Marker([lat,long], tooltip = name ).add_to(seoul_map)
df=pd.read_excel("서울지역대학교위치.xlsx")
seoul_map = folium.Map(location =[37.55,126.98] , zoom_start= 12)
for name,lat,long in zip(df.대학교,df.위도,df.경도):
folium.Marker([lat,long], tooltip = name ).add_to(seoul_map)
seoul_map
import sys
sys.path
(from numpy.lib.function_base import append)
sys.path : 자신이 만든 모듈 불러와 사용하기
sys.path.append()
sys.argv : 명령 행에서 인수 전달하기
import os
(from os import environ)
os.environ
os.environ : 내 시스템 환경 변수 값을 알고 싶을 때.
os.getcwd() : 디렉터리 위치 돌려받기 -> '/content'
os.chdir() : 디렉터리 위치 변경하기
os.system() : 시스템 명령어 호출하기
import pickle
df.to_csv("aaaaaaaa.csv")
df.to_excel("bbbbbbbbbb.xlsx")
with open("text.pickle","wb") as f:
pickle.dump(df,f)
with open("text.pickle","rb") as f:
data = pickle.load(f)
print (data)
https://www.daleseo.com/python-time/
import time
time.time()
((((time.time()/60)/60)/24)/30)/12 -> 53.46726317286562
time.localtime
time.localtime(time.time()).tm_year -> 2022
import calendar
calendar.prmonth(2022,9)
September 2022
Mo Tu We Th Fr Sa Su
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
calendar.weekday(2022,9,13) -> 1
: (월요일:0, 화요일:1, ... 일요일:6)
import random
random.random() : 0과 1 사이의 소수값을 낸다. -> 0.7376918756152824
li=[]
for _ in range(10):
li.append(random.randint(1,5))
li
-> [1, 3, 3, 4, 4, 2, 4, 5, 5, 1]
random.choice
random.choice([1,2,3,10])
random.choice(range(5))
random.shuffle
data=[1,3,2]
random.shuffle(data)
import webbrowser
webbrowser.open("http://google.com")
:여러 스레드가 프로세스 안에 포함된다.
import time
def long_task():
for i in range(5):
time.sleep(1)
print("working: %s" %i)
print("start")
long_task()
-> start
working: 0
working: 1
working: 2
working: 3
working: 4
-> time.sleep(1)
: 1초씩 대기하고 천천히 출력하라.
import time
def long_task():
for i in range(5):
time.sleep(1)
print("working: %s" %i)
print("start")
for _ in range(5):
long_task()
print("End")
-> start
working: 0
working: 1
working: 2
working: 3
working: 4
working: 0
working: 1
-> long_task()
수행하는데 25초 걸린다.
import time
import threading
def long_task():
for i in range(5):
time.sleep(1)
print("working: %s" %i)
print("start")
threads = []
for _ in range(5):
t = threading.Thread(target = long_task)
threads.append(t)
for t in threads:
t.start()
print("End")
-> 5초안에 빠르게 나옴.
:start와 end가 나오고 그 뒤에 스레드 값 나옴.
import time
import threading
def long_task():
for i in range(5):
time.sleep(1)
print("working: %s" %i)
print("start")
threads = []
for _ in range(5):
t = threading.Thread(target = long_task)
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join()
print("End")
-> t.join()
가 end를 해당 함수 종료될 때까지 기다리게 함.
-> start
working: 0
working: 0
working: 0
working: 0
working: 0
working: 1
working: 1
working: 1
working: 1
working: 1
working: 2
working: 2
working: 2
working: 2
working: 2
working: 3
working: 3
working: 3
working: 3working: 3
working: 4
working: 4working: 4
working: 4
working: 4
End
#내가 한거
def GuGu(n):
li=[]
for i in range(1, 10):
li.append(n*i)
return li
GuGu(2)
-> [2, 4, 6, 8, 10, 12, 14, 16, 18]
#(1)
li = []
def GuGu(x):
for i in range(1,10):
li.append(x*i)
print(li)
print(GuGu(2))
#(2)
def GuGu(num):
return [num*i for i in range(1,10)]
GuGu(2)
#내가 한거
result = 0
for i in range(1,101):
if i % 3 == 0 or i % 5 == 0:
result += i
print(result)
#(1)
i = 0
total = 0
while i < 100:
i += 1
if i%3 == 0 or i%5 == 0:
total += i
print(total)
#(2)
i = 0
total = 0
while i < 100:
i += 1
if i%3 == 0 or i%5 == 0:
total += i
print(total)
#(1)
def getTotalPage(m, n):
return m // n + 1
#(2)
def getTotalPage(m, n):
if m % n == 0:
return m // n
else:
return m // n + 1
getTotalPage(25,10) -> 3