본문 바로가기

개발자 모드/파이썬(python)

파이썬 기초 예제 #3

728x90
# Chapter 03-1
# 숫자형


# 데이터 타입

str1 = "Python"
bool = True
str2 = "Anaconda"
float_v = 10.0
int_v = 7
list =[str1, str2]
dict = {
 "name" : "Machin Learning",
 "version" : 2.0
}

tuple = (7,8,9)
set = {7, 8, 9}

print(list)

# 데이타 타입 출력

print(type(str1))
print(type(bool))
print(type(str2))
print(type(float_v))
print(type(int_v))
print(type(dict))
print(type(tuple))
print(type(set))


# 숫자형 연산자
# 정수 선언

i = 77
i2 = -14
big_int =77777777777777799999999999

# 정수 출력
print(i)
print(i2)
print(big_int)
print()

# 실수 출력type(b)
f = 0.9999
f2 = 3.141592
f3 = -3.9
f4 = 3/9

print(f)
print(f2)
print(f3)
print(f4)
print()


# 연산 실습

i1 = 39
i2 = 939
big_int1 = 777777777777777777777792100
big_int2 = 345354657488132415640
f1 = 1.234
f2 =3.939

print("i1 + i2", i1 + i2 )
print("f1 + f2", f1 + f2 )
print("big_int1 + big_int2", big_int1 + big_int2 )
print()


print("i1 * i2", i1 * i2 )
print("f1 * f2", f1 * f2 )
print("big_int1 * big_int2", big_int1 * big_int2 )
print()


# 형변환 실습

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


# 타입 출력
print(type(a), type(b), type(c), type(d))
print()

# 형 변환
print(float(b))
print(int(c))
print(int(d))
print(int(True))
print(float(False))
print(complex(3))
print(complex('3'))
print(complex(False))

# 수치 연산 함수
print(abs(-7))
x,y = divmod(100,8)  # 많이 사요ㅕㅇ되는 함수
print(x,y)

print(pow(5,3), 5**3)
print()

# 외부 모듈

import math

print(math.pi)
print(math.ceil(5.1))  # x 이상의 수중에서 가장 가까운 정수  , 올림 함수

 

 

결과

 

[Command: python -u C:\python_basic\chapter03_01.py]
['Python', 'Anaconda']
<class 'str'>
<class 'bool'>
<class 'str'>
<class 'float'>
<class 'int'>
<class 'dict'>
<class 'tuple'>
<class 'set'>
77
-14
77777777777777799999999999

0.9999
3.141592
-3.9
0.3333333333333333

i1 + i2 978
f1 + f2 5.173
big_int1 + big_int2 777778123132435265910207740

i1 * i2 36621
f1 * f2 4.860726
big_int1 * big_int2 268609178046325212164449390690594468918708444000

<class 'float'> <class 'int'> <class 'float'> <class 'float'>

6.0
0
12
1
0.0
(3+0j)
(3+0j)
0j
7
12 4
125 125

3.141592653589793
6
[Finished in 0.174s]

728x90