Programming 기초/Coding Test
[python#tip] print()의 end 옵션과 sep 옵션
코딩상륙작전
2023. 7. 6. 14:44
* end 옵션
print(a,b, end ="")는 a, b를 출력하고나서 마지막을 다룬다. end 옵션을 추가하지 않았을 때의 디폴트 값은 개행문자(줄바꿈문자, \n)이다.
word = "abcdef"
print(word[0], word[1])
print(word[0], word[1], end="")
print(word[1], word[2], end=" ")
print(word[2], word[3], end=" ")
-----------------------------------
a b
a bb c c d
* sep 옵션
print(a,b, sep = '')는 a,b 사이를 어떻게 처리할지를 묻는다. sep 옵션을 추가하지 않았을 때의 디폴트값은 띄어쓰기이다.
word = "abcdef"
print(word[0], word[1])
print(word[0], word[1], sep="")
print(word[0], word[1], sep=" ")
print(word[0], word[1], sep=" ")
-------------------------------------
a b
ab
a b
a b