Python 자료형 - 숫자
📌 숫자 자료형
int : 정수(10진수).
float : 실수.
j : 복소수.
print(10) # 10
print(3.14) # 3.14
print(4-2j) # (4-2j)
📌 진수
0b : 2진수.
0o : 8진수.
0x : 16진수.
print(10) # 10
print(0b10) # 2
print(0o10) # 8
print(0x10) # 16
💡 print(0123)
: SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
→ 0으로 시작하는 표현은 진법 표현으로 받아들이기 때문에 오류가 발생함.
📌 10진수를 x진수로 변경(문자열로 변경)
bin( ) : 2진수로 변경.
oct( ) : 8진수로 변경.
hex( ) : 16진수로 변경.
print(bin(10)) # 0b1010
print(oct(10)) # 0o12
print(hex(10)) # 0xa
Python 자료형 - 문자열
📌 문자열
: 단일 인용 부호(') 또는 이중 인용 부호(")
print("hello world") # hello world
📌 이스케이프 문자
\t | 탭(tab) |
\n | 개행 문자(다음 행으로 이동) |
\\ | /(역슬래시) |
\' | '(작은 따옴표) |
\'' | "(큰 따옴표) |
print("hello\tworld") # hello world
print("hello\nworld") # hello
# world
print("hello\\world") # hello\world
print("hello\'world") # hello'world
print("hello\"world") # hello"world
💡 문자열 추가 설명
https://codingrecord2209.tistory.com/79
[Python] 문자열 | 문자열 index | 슬라이싱
문자열 - 문자열에는 순서가 있음. - 즉, index, indexing이라는 개념이 있음. s = "hello world" for i in range(0, len(s)): print(s[i]) # h # e # l # l # o # w # o # r # l # d 문자열 index - 문자열은 음..
codingrecord2209.tistory.com
Python 자료형 - 부울
📌 부울
: True, False를 나타내는 자료형(첫 글자는 '대문자').
💡 0일때만 False, 나머지는 True.
💡 빈 문자열인 경우에만 False, 나머지는 True(공백도 True).
Python 자료형 - list, set, tuple, dict
📌 list, set, tuple, dict
list | tuple | set | dict | |
형태 | [값1, 값2, ... ] | (값1, 값2, ..) | {값1, 값2, ... } | {key1:value1, key2:value2, ...} |
순서 | O | O | X | X |
자료변경 | O | X | O | O |
중복 허용 | O | O | X | O |
💡 list, set, tuple, dict 추가 설명
https://codingrecord2209.tistory.com/26
[Python] list | tuple | indexing, index
list vs tuple : 여러 자료들을 담을 수 있는 자료형. 표기법 순서 자료변경 list [ ] O O tuple ( ) O X * tuple 표시할 때 주의할 점 tu = (1) print(type(tu)) # tu = ("abcd") print(type(tu)) # tu = (1,) pr..
codingrecord2209.tistory.com
https://codingrecord2209.tistory.com/93
[Python] set
set : 집합 자료형. { } 중괄호를 사용해 표현. 주의) s = { } → s는 dictionary를 의미. 빈 set을 나타낼 경우, s = set( )이라고 써야 함. - 특징 ① 순서가 없음. → index, indexing, slicing 불가. ② 중..
codingrecord2209.tistory.com
https://codingrecord2209.tistory.com/94?category=1095773
[Python] dict
dict : 자료끼리 관계를 지어줄 때 사용하는 자료형. {key : value} - 특징 ① 순서가 없음. ② key indexing 가능. → key로 value 접근. 이미 존재하는 값이 없을 경우, key indexing으로 값 추가 가능. 이..
codingrecord2209.tistory.com
'Python > Python' 카테고리의 다른 글
[Python] 주석 (0) | 2022.09.06 |
---|---|
[Python] print 함수 (0) | 2022.09.06 |
[Python] 알고 있으면 편한 단축키 (0) | 2022.09.06 |
[Python] Visual Studio Code 추가 설정 (0) | 2022.09.05 |
[Python] Visual Studio Code 설치 및 기본 설정 세팅 (0) | 2022.09.05 |
댓글