xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!
xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!
xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!
xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!
xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!
xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!
xxxxxxxxxx
# Python string арга .format() нь мөр дэх хоосон хаалт ({}) орлуулагчийг аргументуудаараа сольдог.
# Түлхүүр үгсийг орлуулагчид заасан бол аргын харгалзах нэртэй аргументуудаар солино.
msg1 = 'Fred scored {} out of {} points.'
msg1.format(3, 10)
# => 'Fred scored 3 out of 10 points.'
msg2 = 'Fred {verb} a {adjective} {noun}.'
msg2.format(adjective='fluffy', verb='tickled', noun='hamster')
# => 'Fred tickled a fluffy hamster.'
xxxxxxxxxx
# Python3 program to demonstrate
# the str.format() method
# using format option in a simple string
print("{}, A computer science portal for geeks."
.format("GeeksforGeeks"))
# using format option for a
# value stored in a variable
str = "This article is written in {}"
print(str.format("Python"))
# formatting a string using a numeric constant
print("Hello, I am {} years old !".format(18))
OUTPUT:
GeeksforGeeks, A computer science portal for geeks.
This article is written in Python
Hello, I am 18 years old!