์ฑ ์ ์ฝ์ผ๋ฉด์ ๋ชฐ๋๋ ์๋ก์ด ๋ฌธ๋ฒ๋ค์ด ์๊ฒจ์ ์ถ๊ฐ๋ก ๋ฒจ๋ก๊ทธ ์ ๋ฆฌ๋ฅผ ํ๋ ค๊ณ ํ๋ค.
s ="""
def add_(x,y):
return x+y
"""
exec(s)
print(add_(10,20))
#result : 30
num = [1,2,3,4,5]
num.__setitem__(2,99)
print(num)
# result [1,2,99,4,5]
import random
a = [1,2,3,4,55,6,3,22,3,4,76,8,9,39,45]
random.shuffle(a) #๋ฆฌ์คํธ ์๊ธฐ
random.choices(a,k=6) #6๊ฐ๋ฅผ ๋ฝ์์ฃผ๋ ๊ฒ
> ๊ทผ๋ฐ ์ด๋ ๊ฒ ํ๊ฒ ๋๋ฉด ์คํ ํ ๋๋ง๋ค ๊ฐ์ 6๊ฐ์ ๋ฆฌ์คํธ๋ง ๋์จ๋ค
numpy ๋ชจ๋์ ์ฌ์ฉํ๋ฉด ํด๊ฒฐ์ด ๊ฐ๋ฅํ๋ค!
(ํ์ด์ฐธ์์ ๋ํผ ๋ชจ๋์ ์ค์นํ๋๋ฐ ์คํ์ด ์๋๋ค ,, ๐๐)
import numpy as np
a = [1,2,3,4,55,6,3,22,3,4,76,8,9,39,45]
random.shuffle(a,random = np.random.random)
random.choices(a,k=6)
#๋ํผ๋ฅผ ์ํฌํธํ๊ณ ์คํํ๋ฉด ๋๋ฆด ๋๋ง๋ค ๋ค๋ฅธ ๊ฐ์ด ๋์จ๋ค.
x, *y = (1,2,3)
print(x,y)
#result : (1, [2,3])
* ๋ฃ์ผ๋ฉด ๊ฐ๋ณ ์ธ์๋ก ๋ฐ์ ์ ์์
_,a = 100,200
print(a) #100
print(_) #200
for _ in range(2):
print("Hello")
#result : "Hello" "Hello"
import itertools as it
ls = [1,2,3,4]
bs = [4,5,6,7]
for i in it.chain(ls,bs):
print(i)
itertool ๋ชจ๋ ํ์ฑํ 1,2,3,4,4,5,6,7 ์ด ํ์ค๋ก