06 built-in-type

Built-in Types

  • Built-in Types docs 보면 다음과 같은 Python의 기본 자료형을 확인할 수 있다.
    1. Boolean Types: 참(True) 또는 거짓(False) 값 또는 1과 0의 숫자값으로도 표현
    2. Numeric Types: int(정수), float(실수), complex(복소수)
    3. Iterator Types: iter(), next()(컨테이너 또는 이터레이터에 대하여 반복
    4. Sequence Types: list, tuple, range (산술연산, indexing 같은 Sequence Operations을 수행)
    5. Text Sequence Type:str (String Methods를 수행)
    6. Set Types:set, frozentset(정렬되지 않은 유일한 개체의 모음)
    7. Mapping Types:dictionary(연관배열의 키와 값의 쌍의 집합형 자료형
  • 변경 가능형 : list, dict, set 변경 불가능형 : int, float, complex, bool, tuple, str

Boolean Types

In [1]:
a = True
print(type(a))
print(bool(a))
<class 'bool'>
True
In [2]:
b = False
print(type(b))
print(bool(b))
<class 'bool'>
False

Numeric Types

In [3]:
# Python에는 정수나 실수형도 객체로 인식한다.
c = 3
print(type(c))
d = 3.3
print(type(d))
<class 'int'>
<class 'float'>

Iterator Types

In [4]:
x = [1,2,3]
type(x)
y = iter(x)
print(type(y))
print(next(y))
print(next(y))
print(next(y))
<class 'list_iterator'>
1
2
3

Sequence Types

In [5]:
a = list(range(1, 6))
print(a)
[1, 2, 3, 4, 5]

Text Sequence Type

In [6]:
a = 'abcde'
for i in a:
    print(i)
a
b
c
d
e

Set Type

In [7]:
s = set (i for i in range(1, 6))
print(s)
{1, 2, 3, 4, 5}

Mapping Types

In [8]:
a = {'k':'v','k2':3}
a.items()
Out[8]:
dict_items([('k', 'v'), ('k2', 3)])


© 2017. All rights reserved.

Powered by ZooFighter v0.12