Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 주피터노트북판다스
- python데이터분석
- 수업기록
- sql연습
- 팀플기록
- python알고리즘
- 파이썬알고리즘
- sql연습하기
- sql따라하기
- 판다스그래프
- 파이썬차트
- SQLSCOTT
- python수업
- 파이썬수업
- 파이썬시각화
- 주피터노트북맷플롯립
- 파이썬
- 주피터노트북데이터분석
- SQL
- 판다스데이터분석
- 데이터분석시각화
- Python
- 맷플롯립
- 파이썬데이터분석
- 파이썬크롤링
- matplotlib
- SQL수업
- 주피터노트북그래프
- 파이썬데이터분석주피터노트북
- 주피터노트북
Archives
- Today
- Total
IT_developers
Python 개념 및 실습 - 모듈(1) 본문
모듈 : 함수나 변수 또는 클래스들을 모아 놓은 파일 . 패키지 정도
모듈 사용하기
- import 모듈명
- import 모듈명 as 별칭
- from 모듈명 import 모듈 함수(특정한 함수)
- from 모듈명 import 모듈 함수 as 별칭
- from 모듈명 import *== import 모듈명
# sys 모듈
import sys
print(sys.builtin_module_names)
파이썬이 기본으로 가지고 있는 모듈 확인
Ctrl + 마우스 오버 : 클래스를 확인 할 수 있음.
# math 모듈
import math # math 안에 있는 모든 것들이 import
print(dir(math))
print(math.__doc__) # ddefined by the C standard # C언어 기반
print(math.ceil(3.14))
print(math.sin(1))
print(math.cos(1))
print(math.floor(2.4))

# 필요한 모듈 함수만 불러오기.
from math import sin, cos, floor, ceil
print(sin(1))
print(cos(1))
print(floor(2.5))
print(ceil(2.5))

# as : 모듈명에 별칭 붙일 때 사용
import math as m
print(m.ceil(3.14))
print(m.sin(1))
print(m.cos(1))
print(m.floor(2.4))

# random 모듈
import random
# 0.0 <= x< 0 ~ 1 리턴
print(random.random())
# 지정한 범위 사이의 임의의 수 리턴
print(random.uniform(10, 20))
# randrange(max) : 0 ~ max 사이의 임의의 수 리턴
# randrange(min,max) : min~ max 사이의 임의의 수 리턴
print(random.randrange(10))
# choice(list) : 리스트 내부의 요소 중에서 임의의 수 리턴
print(random.choice([1, 2, 3, 4, 5, 6, 7]))
# shuffle(list) : 리스트 내부의 요소 섞기
list1 = [1, 2, 3, 4, 5, 6, 7]
print("shuffle 전 ", list1)
random.shuffle(list1)
print("shuffle 후 ", list1)
# sample(list, 숫자) : 리스트 요소 중에서 숫자 만큼 추출
print(random.sample([1, 2, 3, 4, 5, 6, 7], k=2))
# time 모듈
import time
print("지금부터 5초간 정지")
time.sleep(5)
print("프로그램 종료")
'Python' 카테고리의 다른 글
Python 개념 및 실습 - 예외 (0) | 2022.09.13 |
---|---|
Python 개념 및 실습 - 모듈(2) (0) | 2022.09.12 |
Python 개념 및 실습 - 클래스(3) (0) | 2022.09.11 |
Python 개념 및 실습 - 클래스(2) (0) | 2022.09.11 |
Python 개념 및 실습 - 클래스(1) (1) | 2022.09.11 |
Comments