Sduty/python

문자열 escape code(출력), 주석처리

돌멘 2019. 3. 12. 13:34

escape code

\n : new line

\t : tab

\\ : 문자"\"

\' : 단일 부호(')

\" : 이중 부호(")

\r : Carage return

\f : form feed

\000 : null


ex) 문자열 '\' 출력하기

    a = "abc\\d"


주석처리

""", ''' 로 시작하여 """, ''' 끝난다


문자열 출력

print("abc" + "de") -->  abcde

print("=" * 10)  -->  = 가 10개 출력됨


문자열 format

"숫자 %d 는 홀수 입니다." % 3


문자열 format code

%s : string

%c : character

%d : integer

%f : float

%o : 8진수

%x : 16진수

%% : literal


문자열 관련 함수

count : 문자 개수

find : 문자 위치

index : 문자 위치

join : 문자열 삽입

    ",".join('abc')  -->  a,b,c

upper : 대문자로 변경

lower : 소문자로 변경

lstrinp : 왼쪽 공백 자르기

rstrip : 오른쪽 공백 자르기

strip : 양쪽 공백 자르기

replace : 문자열 바꾸기

    a.replace("abc","de")  --> 'abc'를 'de'로 변경

split : 문자열 나누기

    a="a:b:c:d"

    a.split(':')  -->  a,b,c,d