# 난수 모듈 활용
import random
my_num = random.randint(1, 10) # 1~10 사이의 정수 1개를 난수 추출
print(my_num) # 4
# 파일명: my_calculator.py
def num_add(x, y):
return x + y
# 파일명: test.py
import my_calculator as mc
res = mc.num_add(2, 3)
print(res) # 5
import my_calculator as mc
res = mc.num_add(2,3)
print(res) # 5
print("import한 모듈의 __name__: ", mc.__name__) # my_calculator
print("본 py 파일의 __name__: ", __name__) # __main__
# 해당 Python 가상환경의 site-packages 경로 확인법
import sys
for path in sys.path:
print(path)
import math
print(math.ceil(5.21)) # 올림(6)
print(math.floor(-4.11)) # 내림(-5)
print(math.trunc(8.123)) # 소숫점 절사(8)
print(math.fabs(-7)) # 절댓값(7)
print(math.sqrt(4)) # 제곱근(2)
print(math.gcd(14, 21)) # 최대공약수(7)
print(math.lcm(14, 21)) # 최소공배수(42)
print(math.factorial(10)) # 팩토리얼(3,628,800)
import random
print(random.randint(1, 100)) # 1~100 사이 정수(70)
print(random.random(2)) # 0~1 사이 소수(0.778199957037151)
print(random.choice(["a","b","c"])) # 리스트 내 원소 (b)
import time
print(time.localtime().tm_hour) # 현재 시간(7)
print(time.localtime().tm_min) # 현재 분(51)
print(time.localtime().tm_wday) # 현재 요일(2, 수요일)
*이 글은 제로베이스 데이터 취업 스쿨의 강의 자료 일부를 발췌하여 작성되었습니다.