代码
formatter = "{} {} {} {}"
print("1 - " + formatter.format(1, 2, 3, 4))
print("2 - " + formatter.format("one", "tow", "three", "four"))
print("3 - " + formatter.format(True, False, False, True))
print("4 - " + formatter.format(formatter, formatter, formatter, formatter))
print("5 - " + formatter.format(
"Try your",
"Own text here",
"Maybe a poem",
"Or a song about fear"
))
print("6 - " + formatter.format(1,2,3,44,5))
遇到问题
In exercise 8, functoion ‘formatter’ has 4 parameters. If I put 3 or less parameters in ‘formatter’, and python it in PowerShell. You will see the notice like this:“tuple index out of range”.
学到的
1、简单函数的概念".format()";
2、函数中的参数,带"“的是显示字符串,直接打印出来,不带”"的,如果是python的关键字,也会直接打印出来,否则是会被当做变量。