[파이썬-문법] print 활용 옵션 정리(sep=, end=, format, escape, raw string, f-string)
조사하는김에 정리 sep='값' : print 출력값 사이 연결 end='값' : print 출력값 이후 출력 값.format() : 특정 값 삽입 escape : \n(개행), \t(탭) 등 sep, end, format 소스 복사해서 출력해보면 느낌이 올거다. #sep print('a', 'b', 'c', sep='$$$$$') #출력값 #a$$$$$b$$$$$c #end print('a', 'b', 'c', end='\n$$$$$\n') #출력값 #a b c #$$$$$ #format print('{} 앤드 {}'.format('coffee', 'donut')) #출력값 #coffee 앤드 donut escape 종류 print 구문에서 특수문자를 표현하려면 \(백슬래시)를 붙여줘야된다. \n : ..
2022. 5. 26.
[파이썬 에러잡기] TypeError: string indices must be integers, IndexError: string index out of range 에러 해결
TypeError: string indices must be integers 에러 의미 직역 그대로다. index_t에 'abcde'라는 str(문자열)을 담았다. index_t[0]은 'a' 다. 그리고 0,1,2,3,4 는 1~5번째의 값을 의미한다. (왜냐. 컴터는 0부터 세니까, 다 아시겠지마는) 무튼 string indices must be integers 에러는 문자열의 인덱스 즉[값]에 정수만 넣으라는 의미다. 문자열의 값은 0(첫번째 데이터), 1(두번째 데이터) 가져오는데 1.1, 1.2 이러면 'a'도 아니고 'b'도 아니니 에러가 나는것이다. string index out of range 에러는 아래 그림과 같이 'a', 'b', 'c', 'd', 'e' 5개의 데이터만 있는데 범위를..
2022. 5. 23.