공부합시다!/python

3. Data Type과 형변환

간서치 2023. 1. 17. 14:50
728x90

오늘은 Python Data Type 및 연산에 대해서 알아보겠습니다.

물론 뒤에서 개별 Data Type 챕터에서 더 자세하게 다루게 됩니다.

 

# Data Type

v_str1= "Nice Babo"
v_bool= True
v_str2= "Bad Babo"
v_float=10.3
v_int=8
v_dict={
  "name": "Kim",
  "age": 52
}
v_list=[3,5,7]
v_tuple=3,5,7
v_set={7,8,9}

print(type(v_tuple))
print(type(v_dict))

# 숫자형 및 연산자
'''
  + : 더하기
  - : 빼기
  * : 곱하기
  / : 나누기
  // : 나누기의 (몫)
  % : 나누기의 (나머지)
  ** : 지수(제곱)
  단항 연산자  a++1 -> a=a+1
'''

i1 = 59
i2 = 789
big_i1=999999999999999999999999999999999
big_i2=777777777777777777777777777777777
f1 = 1.234
f2 = 3.587
f3 = .6
f4 = 10.

print(i1 * i2)
print(big_i1 * big_i2)
print(f1 ** f2)
print(f3 + f4)

result = f3 + i2
print(result, type(result))

a = 5.
b = 4
c = 10
print(type(a), type(b))
result2 = a + b
print(result2)

# 형변환
# int, float, complex(복소수)

print(int(result2))
print(float(c))
print(complex(3))
print(int(True))
print(int(False))
print(int('3'))
print(complex(False))

y = 100
y += 100
print(y)

# 수치 연산 함수

print(abs(-7))
#n, m = 10, 20
n, m = divmod(100, 8)
print(n,m)

import math

print(math.ceil(5.1))
print(math.floor(3.453))

a = 'hello world\n'
print(a*3)

벌써부터 힘 뺄 필요없습니다.

후다닥 후다닥 넘어 가시면 됩니다.

외우려 하지말고 습관으로 만드세요!

몸이 익히게 -> 자전거를 타는 것처럼

 

Have a nice day!

728x90