python格式化字符记录

跟练书目《笨办法学python3》
案例1

topic = 'monkey'
print(f"let's talk about {topic}.") 

输出

let's talk about monkey.

案例2

A = "apple"
B = "banana"
y = f"{A} and {B}"
print(y)

输出

apple and banana

案例3

hilarious=False
joke_evaluation = "Isn't that joke so funny?! {}"
print(joke_evaluation.format(hilarious))
#"{}".format()是格式化输出的另一种用法

输出

Isn't that joke so funny?! False

案例4("{}".format()的多参数版本)

formatter="{} {} {} {}"
print(formatter.format(1,2,3,4))
print(formatter.format("one","two","three","four"))
print(formatter.format(True,False,True,False))
print(formatter.format(formatter,formatter,formatter,formatter))
print(formatter.format("try your","own text here","maybe a poem","or a song"))

输出

1 2 3 4
one two three four
True False True False
{
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     } {
     }
try your own text here maybe a poem or a song

你可能感兴趣的:(python学习记录,python)