首页 > 解决方案 > 每次重复 for 循环时减少变量

问题描述

stack_ypos每次循环重复时,我都试图让 的值减少 50

def test_cards():
    for i in range(5):
        card_red(stack4_xpos, stack_ypos)
        stack_ypos - 50

test_cards()

虽然它似乎没有做任何事情。

标签: python

解决方案


您没有分配值的变化,因此您的变量不会改变!

def test_cards():
    for i in range(5):
        card_red(stack4_xpos, stack_ypos)
        stack_ypos -= 50 # equivalent to stack_ypos = stack_ypos - 50

test_cards()

推荐阅读