파이썬

print()

김건우_Jonathan 2022. 12. 28. 17:45

print(출력내용, [, sep=구분자] [, end=끝 문자])

  - sep, end는 옵션값으로 필요한 경우에만 설정함

  - sep : 출력내용이 두 값 이상일 경우 구분자를 두 값 사이에 출력함

  - end : 출력내용 마지막에 출력할 문자를 지정함

            (end값 설정하지 않을 경우 기본값으로 개행 문자 적용됨)



print("Python" "is" "powerful")
print("Python", "is", "powerful")
print("Python"+"is"+"powerful")

Pythonispowerful
Python is powerful
Pythonispowerful

 

 

print("Python", "is", "powerful", sep=";")

Python;is;powerful

print("Python", "is", "powerful", end=";")
print("Python", "is", "powerful")

Python is powerful;Python is powerful

 

 

  • 2진수, 8진수, 16진수
구분 접두어 사용 숫자 사용 예 출력함수
16진법 0x 0 ~ 9, a ~ f 0x2f hex(정수)
8진법 0o 0 ~ 7 0o17 oct(정수)
2진법 0b 0, 1 0b1101 bin(정수)
print(0x2f)
print(0o17)
print(0b1101)

47
15
13

print(hex(47))
print(oct(15))
print(bin(13))

0x2f
0o17

0b1101