簡體   English   中英

Python:重置變量

[英]Python: Resetting a variable

對於下面的代碼,在運行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)

創建另一個變量會起作用嗎?

original_start_point = 1000
start_point = original_start_point

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM