Python - 2. 자료형/숫자형

갓김치·2020년 11월 30일
0

Python 기초

목록 보기
2/2

인프런

chapter03-1

파이썬 모든 자료형

  • int: 정수
  • float: 실수
  • complex: 복소수
  • bool: 불린
  • str: 문자열(시퀀스)
  • list: 리스트(시퀀스)
  • tuple: 튜플(시퀀스)
  • set: 집합
  • dict: 사전

데이터 타입 선언

str1 = "Python"
str2 = 'Anaconda'
bool = True
float = 10.0
int = 7
list = [str1, str2]
dict = {
		"name" : "Machine Learning",
        "version" : 2.0 
        #key, value
	    }
tuple1 = (7, 8, 9)
tuple2 = 7, 8, 9
set = {7, 8, 9}

연산자 활용

  • 사칙연산
  • // : 몫
  • % : 나머지
  • abs(x) : 절대값
  • pow(x,y) x ** y : x의 y승

형 변환

a = 3.
b = 6
c = .7
d = 12.7

float(b) # 6.0
int(c) # 0
int(d) # 12
int(True) # 1 / False : 0
float(False) # 0.0
complex(3) # (3+0j)
complex('3') # (3+0j)
complex(False) # 0j

수치 연산 함수

abs(-7) # 7
x, y = divmod(100, 8) # x = 12, y = 4
pow(5,3) # 125
5 ** 3 # 125

외부 모듈 사용

import math

print(math.pi) # 3.14159265358393 
print(math.ceil(5.1)) # x 이상의 수 중에서 가장 작은 정수 = 6
  • 챕터 7, 8쯤에서 다시 다룰 예정
profile
갈 길이 멀다

0개의 댓글