在"学习Python艰难之路的网站上#34;有运动24,我不明白。以下是作者希望我写下来的代码。
print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
poem = """
\tThe lovely world
with logic so firmly planted
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 "This should be five: %s" % five
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
start_point = 10000
beans, jars, crates = secret_formula(start_point)
print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates)
start_point = start_point / 10
print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)
结果如下:
$ python ex24.py
Let's practice everything.
You'd need to know 'bout escapes with \ that do
newlines and tabs.
--------------
The lovely world
with logic so firmly planted
cannot discern
the needs of love
nor comprehend passion from intuition
and requires an explanation
where there is none.
--------------
This should be five: 5
With a starting point of: 10000
We'd have 5000000 beans, 5000 jars, and 50 crates.
We can also do that this way:
We'd have 500000 beans, 500 jars, and 5 crates.
这是否意味着start_point变量替换了函数的started
变量?另外,函数的()括号中是否有变量的特定名称?为了澄清,在secretformula(started)
中,started
只是一个常规变量或具有单独的名称。对不起,如果这很明显(我是菜鸟)。
答案 0 :(得分:0)
这是否意味着start_point变量取代了"已启动"变量的功能?
参数是如何工作的,是的。但您可以说,started
被赋予start_point
的值。
函数的()括号中的变量是否有特定名称
不在代码中,没有。该名称仅提高了对开发人员的可读性
in" secretformula(已启动)",将"开始"只是一个常规变量或具有单独的名称
它是该引号中的参数,它是secret_formula(start_point)