Blog Full Notice
back to main page

최대 1 분 소요

motivation: 백준 공부하면서 알아야 하는 것들 정리

1. python에서 ascii code 변환 방법

오늘 배운 것: ordinal data vs nominal data ordinal data는 순서형, nominal은 명목형 python에서는 ord(‘a’) 하면 ascii code로 변환해줌. c에서 char 변수 하고 변수를 출력하는 것과 같은 것. chr(97)은 ‘a’다.

2. input 받는 방법

a,b = map(int, input().split())

import sys 스트링1개= sys.stdin.readline().rstrip()

# rstrip을 사용하는 이유는, split()strip() 둘다 공백, 개행문자, tab 로 분리해주거나 없애주는데, split()으로 받으면 문자열이 하나여도 list로 받아오기 때문에, sys.stdin.readline().split()[0] 이런 식으로 써야 한다. 그래서 바로 쓰기 위해서 sys.stdin.readline().rstrip()을 쓰는 것이다.

스트링2개 = sys.stdin.readline().split() # 리스트로 받아옴. 정수1개 = int(sys.stdin.readline().rstrip()) 정수1, 정수2 = map(int, sys.stdin.readline().split())

3. int는 truncation한다.

즉 int(-3.14)는 -3, int(3.14)는 3.

4. word.replace(‘before’, ‘after’)

댓글남기기