python 자료형

파이썬의 자료형

1
int_data = 3 #정수형 자료(integer data)

float = 실수

1
float_data = 3.14 #실수형 자료(floating point data)
1
float_data2 = 3
1
float_data2 = 3.

string = 문자형

1
complex_data = 1+5j
1
str_data1 ='hello world'

list [ ] 변경 가능 / tuple ( ) 변경 불가 / dict {}

1
list_data = [1,2,3,4,5,6,7,8,9,10] #list data type
1
tuple_data = (1,2,3,4,5,6,7,8,9,10) #tuple data type
1
dict_data = {0:'toy',1:'book'} #dictionary data
1
whos
Variable       Type       Data/Info
-----------------------------------
complex_data   complex    (1+5j)
dict_data      dict       n=2
float_data     float      3.14
float_data2    float      3.0
int_data       int        3
list_data      list       n=10
str_data1      str        hello world
tuple_data     tuple      n=10
1
2
3
4
5
6
7
8
9
#정수형
a=123
a=-1123
a=0
#실수형
a=1.2
a=4.24E10 #4.12*10^10
a=4.24e10 #4.12*10^10
b=4.24e-10 #4.12*10^(-10)
1
whos
Variable       Type       Data/Info
-----------------------------------
a              float      42400000000.0
b              float      4.24e-10
complex_data   complex    (1+5j)
dict_data      dict       n=2
float_data     float      3.14
float_data2    float      3.0
int_data       int        3
list_data      list       n=10
str_data1      str        hello world
tuple_data     tuple      n=10
1
reset
Once deleted, variables cannot be recovered. Proceed (y/[n])? y
1
whos
Interactive namespace is empty.
1
2
3
4
a=3
b=4
print(a+b) #사칙연산 : +, -, *, /
print(7%3) # 제곱(^) : ** # 나머지 : %
7
1

문자열

1
2
a= "hello 'my' world"
b= 'hello "my" world' #동일한 따음표가 내부에 있으면 오류가 발생한다.
1
whos
Variable   Type    Data/Info
----------------------------
a          str     hello 'my' world
b          str     hello "my" world
1
2
3
4
5
6
7
a= """
P
""
'O'
""
"""
print(a)
P
""
'O'
""
1
2
3
4
a="my"
b="note"
c=a+"_"+b
print(c)
my_note
1
print((c+"/")*5)
my_note/my_note/my_note/my_note/my_note/
1
print(len(a)) # len = Lenth(길이)
2
Author

Hangack

Posted on

2021-11-01

Updated on

2021-11-28

Licensed under

댓글