YYYEJI

[Python] Random 모듈 본문

Python

[Python] Random 모듈

YEJI ⍢ 2022. 11. 3. 18:15
728x90

모듈(module)이란?

모듈이란 함수나 변수 또는 클래스를 모아 놓은 파일입니다.

 

 

Random 모듈을 이용하기 위해서는 Random을 import 해줘야됩니다.

import random

  Random 모듈은 난수를 발생시킵니다.

 

 

import random

print(random.random())              # Floating point
print(random.randrange(1, 10))      # integer

alphabet = ['a', 'b', 'c']
random.shuffle(alphabet)
print(alphabet)                     # Change the order of values ​​in a list
print(random.choice(alphabet))      # Character

실행을 시킬 때마다 결과가 다른 것을 확인할 수 있습니다. 

 

 

 

◡̈

'Python' 카테고리의 다른 글

[Python] Conda 명령어 정리  (0) 2022.11.03
[Python] 맥(MacOS)에서 Conda 설치하기  (0) 2022.11.03
[Python] datetime 모듈  (0) 2022.11.03
[Python] Math 모듈  (0) 2022.11.03
[Python] Pillow(PIL) 모듈  (0) 2022.11.03