๐Ÿ“‚์›น ๊ฐœ๋ฐœ(Web) 48

ํŒŒ์ด์ฌ time ๋ชจ๋“ˆ

time ๋ชจ๋“ˆ ์‹œ๊ฐ„ ์ฒ˜๋ฆฌ์— ๊ด€๋ จ๋œ time ๋ชจ๋“ˆ 1. import time 1970๋…„ 1์›” 1์ผ 0์‹œ 0๋ถ„ 0์ดˆ๋ถ€ํ„ฐ ํ˜„์žฌ๊นŒ์ง€ ๊ฒฝ๊ณผ ์‹œ๊ฐ„์„ ๋ฐ˜ํ™˜ ๋งˆ์ดํฌ๋กœ ์ดˆ print(time.time()) #ํƒ€์ž„ ๋ชจ๋“ˆ์— ํƒ€์ž„ ํ•จ์ˆ˜๊ฐ€ ์žˆ์Œ 2. ctime() ํ•จ์ˆ˜ - ์ธ์ˆ˜๋กœ ์ „๋‹ฌ๋œ time ์‹œ๊ฐ„ ํ˜•์‹์„ ๊ฐ–์ถฐ ๋ฐ˜ํ™˜ print(time.ctime(time.time())) ์ธ์ˆ˜๋กœ ์ „๋‹ฌ๋œ ๋‚ ์งœ์™€ ์ง€์‹œ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ํ˜•์‹์„ ๊ฐ–์ถ˜ ๋‚ ์งœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ print(time.strftime('%Y-%m-%d %H:%M:%S')) #์ŠคํŠธ๋ง ํฌ๋งท ํƒ€์ž„ print(time.strftime('%Y๋…„ %m์›” %d์ผ %H:%M:%S')) #์ŠคํŠธ๋ง ํฌ๋งท ํƒ€์ž„ #๋งŒ์•ฝ ์ธ์ฝ”๋”ฉ ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. print( time.s..

ํŒŒ์ด์ฌ ๋žœ๋ค random ๋ชจ๋“ˆ

import random 1. ๋‘ ์ธ์ˆ˜ ์‚ฌ์ด print(random.randint(1, 10)) # 1 ~ 10 2. range ํ•จ์ˆ˜ print(random.randrange(10)) # 0 ~ 9 print(random.randrange(1, 10)) # 1 ~ 9 print(random.randrange(1, 10, 2)) # 1 ~ 9 ํ™€์ˆ˜๋งŒ, 1+2 ์ฆ๊ฐ 3. 0 ์ด์ƒ 1 ๋ฏธ๋งŒ print(random.random()) if random.random()

ํŒŒ์ด์ฌ ํ‘œ์ค€ ๋ชจ๋“ˆ

ํ‘œ์ค€๋ชจ๋“ˆ ํŒŒ์ด์ฌ์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‹ค์น˜๋˜์–ด ์žˆ๋Š” ๋ชจ๋“ˆ # math - ์ˆ˜ํ•™ ๊ด€๋ จ ๋ชจ๋“ˆ import math 1. ์›์ฃผ์œจ print(math.pi) 2. ์˜ฌ๋ฆผ print(math.ceil(1.1)) 3. ๋‚ด๋ฆผ print(math.floor(1.9)) 4. ์ •์ˆ˜๋กœ ์ ˆ์‚ญ print(math.trunc(1.9)) #์ ˆ์‚ญ print(math.floor(1.9)) #๋‚ด๋ฆผ print(math.ceil(1.9)) #์˜ฌ๋ฆผ 5. ์ œ๊ณฑ๊ทผ print(math.sqrt(25)) 6. ์ œ๊ณฑ print(math.pow(2, 3))

ํŒŒ์ด์ฌ ๋ชจ๋“ˆ(module)

๋ชจ๋“ˆ(module) ๋ณ€์ˆ˜๋‚˜ ํ•จ์ˆ˜ ๋˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋ชจ์•„ ๋†“์€ ํŒŒ์ผ์„ ๋ชจ๋“ˆ์ด๋ผ๊ณ  ํ•œ๋‹ค. **์‚ฌ์šฉํ•  conveter ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๋‘”๋‹ค. MILES = 0.621371 POUND = 0.00220462 def kilometer_to_miles(kilometer): return kilometer * MILES def gram_to_pounds(gram): return gram * POUND 1. ๋ชจ๋“ˆ ์‚ฌ์šฉ๋ฒ• import ๋ชจ๋“ˆ๋ช… import convertermiles = converter.kilometer_to_miles(150) print('150km = {}miles'.format(miles)) pounds = converter.gram_to_pounds(1000) print('1000g={}pounds'.fo..

ํŒŒ์ด์ฌ ํ•จ์ˆ˜(function)

ํ•จ์ˆ˜(fuction) ํ•˜๋‚˜์˜ ํŠน๋ณ„ํ•œ ๋ชฉ์ ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋…๋ฆฝ์ ์œผ๋กœ ์„ค๊ณ„๋œ ํ”„๋กœ๊ทธ๋žจ ์ฝ”๋“œ์˜ ์ง‘ํ•ฉ def ํ•จ์ˆ˜ ์ด๋ฆ„(๋งค๊ฐœ๋ณ€์ˆ˜) ์ฝ”๋“œ ์‹คํ–‰๋ฌธ return ๋ฐ˜ํ™˜๊ฐ’ 1. ๋งค๊ฐœ๋ณ€์ˆ˜ x ๋ฆฌํ„ด x # welcome() ํ•จ์ˆ˜ ์ •์˜(์‹คํ–‰ x) def welcome(): print('Hello Python') print('Nice to meet you') welcome() # ํ•จ์ˆ˜ ํ˜ธ์ถœ(์‹คํ–‰) 2. ๋งค๊ฐœ๋ณ€์ˆ˜ o ๋ฆฌํ„ด x def introduce(name, age): print('๋‚ด ์ด๋ฆ„์€ {}์ด๊ณ , ๋‚˜์ด๋Š” {}์‚ด ์ž…๋‹ˆ๋‹ค.'.format(name,age)) introduce('ํ‚น๋‰ด๋•ก', 30) ๊ฐ€๋ณ€ ๋งค๊ฐœ๋ณ€์ˆ˜ ํ•จ์ˆ˜ def show(*args): print(type(args)) for item in args: print..

ํŒŒ์ด์ฌ ๊ต์ง‘ํ•ฉ intersection() ํ•ฉ์ง‘ํ•ฉ union() ์ฐจ์ง‘ํ•ฉ difference()

1. ๊ต์ง‘ํ•ฉ intersection() s1 = {'apple', 'banana', 'cherry'} s2 = {'apple', 'banana', 'orange'} print(s1 & s2) result = s1.intersection(s2) print(result) 2. ํ•ฉ์ง‘ํ•ฉ union() s1 = {'apple', 'banana', 'cherry'} s2 = {'apple', 'banana', 'orange'} print(s1 | s2) result = s1.union(s2) print(result) 3. ์ฐจ์ง‘ํ•ฉ difference() s1 = {'apple', 'banana', 'cherry'} s12= {'apple', 'banana', 'orange'} print(s1 - s2) result ..

join ๋ฉ”์†Œ๋“œ /split ๋ฉ”์†Œ๋“œ /replace ๋ฉ”์†Œ๋“œ /strip(), lstrip(), rstrip() ๊ณต๋ฐฑ ์ œ๊ฑฐ

1. join() ๋ฉ”์†Œ๋“œ s = '-'.join('python') print(s) s = '+'.join(['a', 'b', 'c', 'd', 'e']) print(s) s = ''.join(['a', 'b', 'c', 'd', 'e']) print(s) 2. split() ๋ฉ”์†Œ๋“œ s = 'Life is too short' result = s.split() print(result) s = '010-1234-5678' result = s.split('-') print(result) print(result[2]) #๋’ท๋ฒˆํ˜ธ๋งŒ data = 'ํ‚น๋‰ด๋•ก|30|ํ•™์ƒ' result = data.split('|') print(result) print('์ด๋ฆ„ : {}'.format(result[0])) 3. replace(..

ํŒŒ์ด์ฌ ๋ฉ”์†Œ๋“œ(method)/string๊ฐ์ฒด format ๋ฉ”์†Œ๋“œ/find ๋ฉ”์†Œ๋“œ/count ๋ฉ”์†Œ๋“œ/find ๋ฉ”์†Œ๋“œ/ index ๋ฉ”์†Œ๋“œ

๋ฉ”์†Œ๋“œ(method) ํŠน์ • ๊ฐ์ฒด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ•จ์ˆ˜๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด์„œ๋งŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜ 1. String ๊ฐ์ฒด format ๋ฉ”์†Œ๋“œ print("10์ž๋ฆฌ ํญ ์™ผ ์ชฝ ์ •๋ ฌ ' {:10d}".format(123)) print("10์ž๋ฆฌ ํญ ๊ฐ€์šด๋ฐ ์ •๋ ฌ ์ฑ„์›€๋ฌธ์ž ' {:*^10d}".format(123)) 2. count() ๋ฉ”์†Œ๋“œ ์ฒซ ๋ฒˆ์งธ : ๋ฌธ์ž์—ด.count(x)๋Š” ๋ฌธ์ž์—ด ์ „ ๋ฒ”์œ„์—์„œ x๊ฐ€ ๋“ฑ์žฅํ•˜๋Š” ํšŸ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ ๋‘ ๋ฒˆ์งธ : ๋ฌธ์ž์—ด.count(x, start)๋Š” ๋ฌธ์ž์—ด start index ๋ถ€๋ถ„์—์„œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ๋ฌธ์ž์—ด ๋๊นŒ์ง€ x๊ฐ€ ๋“ฑ์žฅํ•˜๋Š” ํšŸ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ ์„ธ ๋ฒˆ์งธ : ๋ฌธ์ž์—ด.count(x, start, end)๋Š” ๋ฌธ์ž์—ด start index ๋ถ€๋ถ„์—์„œ end index ๋ถ€๋ถ„๊นŒ์ง€์˜..

python ๋‚ด์žฅ ํ•จ์ˆ˜ ๋ฌธ์ž์—ด/์ฒœ๋‹จ์œ„ ์‰ผํ‘œ/์ ˆ๋Œ€๊ฐ’/์ตœ๋Œ€๊ฐ’/์ตœ์†Œ๊ฐ’/๊ฑฐ๋“ญ์ œ๊ณฑ/์˜ค๋ฆ„์ฐจ์ˆœ์ •๋ ฌ/์—ญ์ •๋ ฌ/zipํ•จ์ˆ˜

๋‚ด์žฅํ•จ์ˆ˜ ๋ณด์ถฉ 1. format์œผ๋กœ ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ result = format(10000) #str(10000)๊ณผ ๊ฐ™๋‹ค print(type(result)) 2. ์ฒœ ๋‹จ์œ„ ์‰ผํ‘œ result = format(10000, ',') print(result) 3. abs() ์ ˆ๋Œ€๊ฐ’ result = abs(10) print(result) result = abs(-10) print(result) 4. max() ์ตœ๋Œ€๊ฐ’ ๋ฐ˜ํ™˜ result = max(1,10) print(result) li = [5, 3, 7, 4, 2, 1] result = max(li) print(result) 5. min() ์ตœ์†Œ๊ฐ’ ๋ฐ˜ํ™˜ result = min(li) print(result) 6. pow() ๊ฑฐ๋“ญ์ œ๊ณฑ ํ•จ์ˆ˜ result = pow(1..

ํŒŒ์ด์ฌ enumerate() ๋‚ด์žฅ ํ•จ์ˆ˜

enumerate() List, Tuple, String ๋“ฑ ์ž๋ฃŒํ˜•์„ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด ์ธ๋ฑ์Šค ๊ฐ’์„ ํฌํ•จํ•˜๋Š” enumerate ๊ฐ์ฒด๋ฅผ ๋Œ๋ ค์ค€๋‹ค. ๋ฆฌ์ŠคํŠธ์˜ ์›์†Œ์— ์ˆœ์„œ๊ฐ’์„ ๋ถ€์—ฌํ•ด์ฃผ๋Š” ํ•จ์ˆ˜. months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] print(len(months)) for month, day in enumerate(months): print('{}์›” = {}์ผ'.format(month+1, day))