파이썬 자료형의 참(True)과 거짓(False)
자료형 |
참(True) |
거짓(False) |
숫자 |
0이 아닌 정수 |
0 |
문자열 |
'python' |
'' |
리스트 |
['a','b','c'] |
[ ] |
튜플 |
('a','b','c') |
( ) |
딕셔너리 |
{'a':'b'} |
{ } |
1. 문자열
if 'python':
print(True)
else:
print(False)
----------------
True
if '':
print(True)
else:
print(False)
----------------
False
2. 숫자
if 123:
print(True)
else:
print(False)
----------------
True
if 0: # 0 -> False
print(True)
else:
print(False)
----------------
False
3. 리스트
if ['a']:
print(True)
else:
print(False)
----------------
True
if []:
print(True)
else:
print(False)
----------------
False
4. 튜플
if ('a'):
print(True)
else:
print(False)
----------------
True
if ():
print(True)
else:
print(False)
----------------
False
5. 딕셔너리
if {'a':1}:
print(True)
else:
print(False)
----------------
True
if {}:
print(True)
else:
print(False)
----------------
False
'Python > Python Programming' 카테고리의 다른 글
[Python] MSSQL 실행쿼리 모니터링 (0) | 2018.05.11 |
---|---|
[Python] ftplib 모듈을 이용한 FTP 파일 업로드 (0) | 2018.05.09 |
[Python] Assigning variables or list as single-line if statements (한줄if문) (0) | 2018.05.07 |
[Python] 포함(Containment) 연산자 in, not in (2) | 2018.05.07 |
[Python] getpass 모듈을 이용하여 입력값 감추기 (0) | 2018.05.06 |
[Python] set 자료형 - 교집합, 합집합, 차집합 (0) | 2018.05.06 |
[Python] Remove list duplicates using set data type. (파이썬 집합 자료형(set)을 이용한 리스트 중복값 제거) (0) | 2018.05.06 |
[Python] 파이썬 requests 모듈로 json 처리하기 (0) | 2018.05.05 |