개발 이야기/TIL
-
23.01.02 python print개발 이야기/TIL 2023. 1. 2. 20:36
#문제 다음 경로를 출력하시오. "C:\Download\'hello'.py" (단, 따옴표도 함께 출력한다.) 풀이: print("\"C:\\Download\\'hello'.py\"") 해설: python에서 print는 기본적으로 print(" "), print(' ') 형태로 쓰는 것이 일반적이다(물론 print()만 사용하여도 자동으로 str()을 붙여주기는 한다) 그렇기에 ""을 내부에 출력해야하는 경우 조심해야한다. 이때 우리가 출력하고자하는 따옴표는 \를 앞에 붙여주어 이것이 출력하고자하는 문자임을 표시해준다. 동시에 문제에서는 \가 출력하고자 하는 문자 안에 있기에 이는 \\로 변경해 안전하게 출력해준다. 추가: print의 관한 몇몇 내용 https://www.daleseo.com/pyth..