본문 바로가기
Common /Python

[Python] 외부 모듈 사용하기

by 언덕너머에 2017. 7. 2.

외부에서 모듈을 가져와 사용할려면 import를 사용해야 한다.


예를 들어 수학관련 함수 math를 사용할려면 다음과 같다.

import math


r = 10

circleValue = 2 * math.pi * r


print(circleValue)

62.83185307179586


다음은 random함수 예이다.

random함수는 실행될때마다 정의된 값중 임의의 값이 반환된다.

import random


candidates = ["가위", "바위", "보"]

selected = random.choice(candidates)


print(selected)

바위


'Common > Python' 카테고리의 다른 글

[Python] Dictionary 선언 및 사용하기  (2) 2017.07.02
[Python] 모듈 만들기  (0) 2017.07.02
[Python] for  (0) 2017.06.24
[python]list에 사용되는 Method or 연산자  (0) 2017.06.24
[Python]배열 - list  (0) 2017.06.18