24.更多的练习——.format(*formula)
前言
输出格式化方法中的*。
一、Atom文本编辑器
print("Let's practic everything.")
print("You\'d need to koow \'bout escapes with \\ that do:")
print('\n newline and \t tabs.')
poem = """
\tThe lovely world
with logic so firmly plante
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none
"""
print("----------------")
print(poem)
print("----------------")
five = 10 - 2 + 3 - 6
print(f"This should be five: {five}")
def secrte_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
start_point = 10000
beans, jars, crates = secrte_formula(start_point)
# remember that this is another way to formula a string.
print("With a starting point of {}".format(start_point))
# it's just like with an f" " string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
start_point = start_point / 10
print("We can alos da that this way:")
formula = secrte_formula(start_point)
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, {} crates.".format(*formula))
二、运行Python程序
在Window上键入Python就可以看到结果。
python ex24.py
总结
以上内容介绍了Python的字符串、函数的练习,有关Python、数据科学、人工智能等文章后续会不定期发布,请大家多多关注,一键三连哟(●’◡’●)。