1. 파라미터 출력
# format() 사용
print ( "{0} first, {1} second".format("1","2"))
print ( "{} first, {} second".format("1","2"))
print ( "{first} first, {second} second".format(first="1",second="2" ))
# % 사용
print("%d first, %s second" % (1, "2"))
# "+" 이용
print ( "1" + " first, " + "2" + "sencond")
# 소수점 이하 셋째, 넷째자리
print ( "{0:.3f}".format(1.0/3))
print ( "{0:.4f}".format(1.0/3))
# 12자리를 "_"으로 채움 ( 가운데, 왼쪽, 오른쪽 )
print ('{0:_^12}'.format('center'))
___center___
print ('{0:_>12}'.format('center'))
______center
print ('{0:_<12 center="" format="" p="">12>
center______
# "\" 사용
print ( 'Whar\'s your name?')
# 그대로 출력 ( "r", "R" )
print ( r'Whar\'s your name?')
print ( R'Whar\'s your name?')
3. end사용
print("second", end="$$")
print("last", end="")
first**second$$last
4. 여러줄
>>> print ("""first line
... second line""")
... second line""")
댓글 없음:
댓글 쓰기