12. Python

[파이썬 기본편_7] 문자로 인식하게 만드는 법

도피디 2023. 8. 22. 22:08
반응형

위키독스 링크: https://wikidocs.net/13

 

 

 

문자형으로 만드는 4가지 방법

"Hello World"
'Hello World'
"""Life is too short, You need python"""
'''Life is too short, You need python'''

 

 

 

  • 1번
a = "Life is too short, You need Python"
b = "a"
c = "123"
print(type(a))

출력값: <class 'str'>

 

- str: string(문자)의 약자

 

 

 

 

 

  • 2번 (문자열 안에 큰 따옴표를 넣고 싶다면)
a = 'Life is too short, You need "Python"'
print(a)

출력값: Life is too short, You need "Python"

 

 

 

 

 

 

  • 3번 (작은따옴표 앞에 백 슬래쉬 \)
a = 'I\'m hungry'
print(a)

출력값: I'm hungry

 

 

 

 

 

 

  • 4번 (큰 따옴표 앞에 백 슬래쉬 \)
a = "Life is too short, You need \"Python\""
print(a)

출력값: Life is too short, You need "Python"

 

 

 

 

 

반응형