・ Here, I will introduce two.
・ 1, f-string ・ 2, format ()
f-string A character string defined by prefixing with f
a="apple"
f"I like an {a}"#Replace with variable value
Execution result
I like an apple
format() {} In the string is replaced with the value passed to the argument of method str.format ().
a="apple"
"I like an {}".format(a)
Execution result
I like an apple
・ 1.f-string
a="apple"
b="orange"
f"I like an {a} and an {b}"
Execution result
I like an apple and an orange
2.format()
a="apple"
b="orange"
"I like an {} and {}".format(a,b)
Execution result
I like an apple and an orange
Recommended Posts