본문 바로가기

컴퓨터프로그래밍

Python Type

type() : 괄호 안의 type을 보여줌.

ex)

>>>b=type(3.7)

>>>type(b)

<class 'type'>

>>>type(print) #print 함수의 type

<class 'builtin_function_or_method'> #내장함수 또는 method

 

python type

  • boolean-bool: true와 false만을 값으로 가짐. if/while에 주로 사용.
    • python에서 false의 경우
    • none
    • 0
    • 0.0
    • an empty str, '', ""
    • an empty list, []
    • an empty set, set()
    • an empty dict, {}

이 외의 경우는 true

 

 

boolean operators: 대소관계, in 등

  • and(c언어-&&): 하나라도 false가 나오면 뒤에 evaluation을 하지 않음.
  • or(||): 하나라도 true가 나오면 뒤에 evaluation을 하지 않음.
  • not(!)

대소관계: 대문자가 소문자보다 작은 값을 가지며, 알파벳에서 앞에 있는 글자가 작게 처리됨.

ex) abc<abd

membership operator: 반환값 boolean

ex) >>>'a' in 'abc'

     true

 

mutable- 값 수정 가능/ immutable-값 수정 불가능

  • sequence(순서가 중요함. 동일요소 중복포함가능)
    • str: text
    • list[]: item의 index로 순서를 사용함. mutable
    • tuple(): immutable
    • binary(2진법): bytes-immutable byte sequence. binary data를 위한 tuple(하나의 item이 1byte)/ bytearray: mutable byte sequence. binary data를 위한 list (byte처리)
  • set(집합. 순서가 중요하지 않음. 중복요소포함불가)
    • set{}: 수학에서 집합을 abstraction(중복되는 item없고, 순서가 의미없음.) mutable
    • frozenset{}: immutable set (frozen:변경을 못하게 함)
    • dict: key와 value로 구성된 pair{key:value}를 item으로 가지는 collection. key를 통해 value에 접근(순서의미없음)  key-immutable, value-mutable.

'컴퓨터프로그래밍' 카테고리의 다른 글

control structure  (0) 2024.05.20
expression, statement  (0) 2024.05.20
VSCODE  (0) 2024.05.13
OOP  (0) 2024.05.07
programming 소개  (0) 2024.05.01