#전역변수 global : 함수 안과 밖에서 모두 사용 가능한 변수
def hello():
print(name + ', 안녕!')
name = '예찬'
hello()
print(name)
#지역변수 local : 함수 안에서만 사용 가능한 변수
def bye():
name2 = '예찬'
print(name2 + ', 잘 가')
bye()
# print(name2)
x = 5 #전역변수
def add():
global x
x = 8 #전역변수
y = 3 #지역변수
print(x, y)
print('x + y =', x + y)
add()
print(x)
# print(y)
c = 5
def C():
c = 3
print(c) #3
C()
print(c) #5
def s():
global x
x = 1
y = 5
print(x) #1
print(y) #5
x = 10
s()
print(x) #1
# print(y)
print('----모듈----')
#모듈 : 프로그램에서 사용할 함수, 변수, 자료들을 미리 모아둔 것
import random
print(dir(random))
print(random.randint(1, 100)) #1~100 사이의 랜덤 정수 생성
print(random.random()) #0~1 사이의 랜덤 실수 생성
print(random.choice('apple')) #시퀀스 원소 중 하나를 반환
print(random.sample('apple', 3)) #시퀀스 원소 중 i개 반환
print(random.sample(range(1, 51), 5))
import math
print(dir(math))
print(math.pi)
print(math.pow(2, 3)) #2의 3제곱
print(math.ceil(2.2))
print(math.floor(4.9))
from math import sqrt #모듈의 특정 함수만 가져오기
print(sqrt(9))
import time as t #모듈 별명 만들기
print(dir(t))
print(t.localtime())
print(t.time())
t.sleep(3)
To embed this project on your website, copy the following code and paste it into your website's HTML: