Python:重置变量

时间:2015-12-02 10:42:31

标签: python python-2.7

对于以下代码,在运行start_point = start_point / 10之后,其值将降至1,000,如果随后调用它将保持不变。

我可以知道如何将其重置为原来的10,000吗?我相信一种方法是设置一个全局变量。但是有更简单的方法吗?像seek(0)

def secret_formula(started):
    jelly_beans = started * 500                 
    jars = jelly_beans / 1000                   
    crates = jars / 100                         
    return jelly_beans, crates, jars                

start_point = 10000
item_1, item_2, item_3 = secret_formula(start_point)

print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (item_1, item_2, item_3)

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)

1 个答案:

答案 0 :(得分:1)

会创建另一个变量吗?

original_start_point = 1000
start_point = original_start_point