# 전역변수 global : 함수 밖에서 정의된 변수
def hello():
    print(name)
name = '주현'
hello()
print(name)

# 지역변수 local :함수 안에서 정의된 변수
def A():
    a = 5
    print(a)

A()
# print(a)

b = 5
def B():
    b = 3
    print(b) 
print(b) # 5
b = 1
B() # 3
print(b) # 1

def add():
    global y
    y = 7 #전역변수
    print(x + y)
x = 8 #전역변수
add()
print(x)
print(y)

c = 10
def C():
    global c
    c = 20
    print(c)
print(c) #10
C() #20
print(c) #20
c = 30
C()
print(c) #20

print('----모듈----')
import math 

print(dir(math))
print(math.pi)
print(format(math.pi, '.20f'))
print(math.sqrt(9)) #제곱근
print(3 ** 2)
print(math.pow(3, 2))

from time import localtime #모듈에서 사용하는 하나만 가져오기
import time

print(localtime())
print(dir(time))
print(time.time())
# time.sleep(2.5)

import random as r #모듈 별명 만들어서 사용하기

print(dir(r))
print(r.randint(1, 10))
print(r.random())
print(r.choice('apple'))
print(r.sample(('apple'), 3))

from math import sqrt as s #math라는 모듈에서 sqrt라는 함수를 가져와서 s라고 호칭한다
print(s(9))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: