728x90
예제로 보는 Python
C언어를 안다면 정독만 해도 문법 숙지 가능!!
파격적 정리!!
입출력
# 입력: 기본적으로 str type으로 입력받기 때문에 int형으로 형변환이 필요하다.
num = int(input())
# int(input("숫자를 입력해주세요.")) # = 문자열 출력 후 다음 줄에서 입력받음
# 출력, print 후 줄바꿈이 같이 됨.
print(num, "숫자입니다.")
# 위의 방법이 권장되나 C의 형태로도 사용 가능
print("%d" %num) # (= in C lang) (= printf("%d\n", num);)
데이터 타입
Text Type: | str |
Numeric Types: | int, float, complex |
Sequence Types: | list, tuple, range |
Mapping Type: | dict |
Set Types: | set, frozenset |
Boolean Type: | bool |
Binary Types: | bytes, bytearray, memoryview |
# 변수의 데이터 타입을 확인하는 함수
type(variable_name)
# 문자열은 ', " 상관 없음. "~~", '~~'
# boolean을 사용할 때는 True, False (대소문자 구별)
연산자
+, -, *,
/ : 나누기, 실수의 형태
// : 나누기, 몫
% : 나머지
관계 연산자 (>, <, >=, <=, ==, !=)
논리 연산자 (&& and, || or, ! not)
비트 연산자 (&, |, ^, ~, <<, >>)
https://www.w3schools.com/python/python_datatypes.asp
Python Data Types
Python Data Types Built-in Data Types In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories:
www.w3schools.com
728x90
'언어 > python' 카테고리의 다른 글
[Python] 배열, tuples, dictionary, set (0) | 2022.04.25 |
---|---|
[Python] 배열, List (0) | 2022.04.13 |
[Python] 문자열 (0) | 2022.04.05 |
[Python] 함수 (0) | 2022.03.29 |
[Python] 조건문과 반복문 (0) | 2022.03.29 |
댓글