[Python] print 이해하기

데린이·2022년 3월 21일
0

print(str)는 str을 출력하는 함수이다.
위 함수의 특징을 나열하고자 한다.

  1. '+' 와 , 의 차이
print('Hello','World')
print('Hello' + 'World')
[Result]
Hello World
HelloWorld
+를 사용해서 string끼리 먼저 합쳐놓고 print를 하게되면 공백없이 문자열이 출력된다.

참고로, string*int를 하면 int만큼 string이 반복되어 출력된다. 
print('Hello'*3)
[Result]
HelloHelloHello
  1. '," 출력하기

    • '를 출력하려면 ""를 사용; print(" ' ")
    • "를 출력하려면 ''를 사용; print(' " ')
  2. sep 활용하기

    sep parameter로 print 두개 이상의 입력 사이에 특정 글자를 넣을 수 있다.

print('a','b',sep=':')
print('a','b','c',sep=':')
[Result]
a:b
a:b:c
profile
취뽀를 기원하는 취준생입니다!

0개의 댓글