728x90
반응형

조사하는김에 정리

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 : 개행
\t : 탭(
\\ : '\' 
\' : 쿼터
\" : 더블쿼터

 

**Raw string과 F-string 활용


Raw String은 print('내용') 구문 내 특문을 전부 무시해준다.(매우 중요)


특문이 많은 문장을 복붙하거나, 데이터 분석 시 아래와 같은 상황에서는
각 \n 개행마다 텍스트 출력위해 \\n으로 바꿔주기 귀찮다.
ex1) print('1111\\n222\\n1111\\n222\\n1111\\n222\\n1111\\n222\\n1111\\n222\\n')

고로 r을 붙여서 raw string으로 쉽게쓰자
ex2) print(r'1111\n222\n1111\n222\n1111\n222\n1111\n222\n1111\n222\n1111\n222\n')

F-String은 format 기법을 효율적 사용 방안이다. (3.6버전 이상 지원한다.)

txt = 'aaa'
output = f'Its {txt}'
print(output)
# Its aaa

a = 1
b = 2
output = f'합 : {a+b}'
print(output)
# 합 : 3

#참고 https://brownbears.tistory.com/421

그렇다.

 

-끝-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형

+ Recent posts