Python format()

1 개요[편집]

Python format()
print("Hello, {}!".format("World"))
# Hello, World!
print("Hello, {} {}!".format("My","Friend"))
# Hello, My Friend!
print("Hello, {} {}!".format(1,2))
# Hello, 1 2!
print("Hello, {0} {1}!".format("My","Friend"))
# Hello, My Friend!
print("Hello, {1} {0}!".format("My","Friend"))
# Hello, Friend My!
print("My name is {name} and I am {age} years old.".format(name="John", age=5))
# My name is John and I am 5 years old.
name = "John"
age = 5
print("My name is {name} and I am {age} years old.".format(name=name, age=age))
# My name is John and I am 5 years old.
name = "John"
age = 5
print("My name is {name} and I am {age} years old. Please call me {name}.".format(name=name, age=age))
# My name is John and I am 5 years old. Please call me John.
name = "John"
age = 5
print(f"My name is {name} and I am {age} years old. Please call me {name}.")
# My name is John and I am 5 years old. Please call me John.

2 같이 보기[편집]

3 참고[편집]

편집자 Jmnote
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}