상세 컨텐츠

본문 제목

print, f-string formatting

Python

by techbard 2024. 12. 3. 10:13

본문

반응형

"""

Box print

"""

 

def boxPrint(symbol, w, h):

print(symbol * w)

 

for i in range(h -1):

print(symbol + (' ' * (w - 2) + symbol))

 

print(symbol * w)

 

boxPrint('*', 15, 5)

 

# 결과

 

 

# f-strings formatting (Python 3.6+)
# ====================
# - Formatted string literals (i.e., f-strings) provide a way
# to embed expressions inside string literals, using a minimal
# syntax.
# - It works by adding a 'f' char at the begining of a string,
# and then a placeholder '{}' which can contain variables,
# functions, etc. to format the value.
# Cleaner and easier to write.

 

반응형

관련글 더보기

댓글 영역