Python 增量语法错误,即使它应该是正确的

Python 增量语法错误,即使它应该是正确的,python,python-2.7,pygame,Python,Python 2.7,Pygame,这可能是由于一些我无法识别的愚蠢错误造成的,但是当我运行以下代码时,Python会返回一个语法错误 # Imports import pygame import os # Startup pygame.init() # Screen size = (500, 500) screen = pygame.display.set_mode(size, pygame.NOFRAME) pygame.display.set_caption = ("Swinger") pygame.mouse.set_

这可能是由于一些我无法识别的愚蠢错误造成的,但是当我运行以下代码时,Python会返回一个语法错误

# Imports
import pygame
import os

# Startup
pygame.init()

# Screen
size = (500, 500)
screen = pygame.display.set_mode(size, pygame.NOFRAME)
pygame.display.set_caption = ("Swinger")
pygame.mouse.set_visible(False)
clock = pygame.time.Clock()
# -- Assign Functions --
# -- Assign Classes --
# -- Assign Variables --
#Sets the color of pure white to a variable to be called
WHITE    = (255, 255, 255)
#Sets the player to an image loaded from os path Swinger
Player = pygame.image.load(os.path.join("Swinger", "player.png"))
Pointer = pygame.image.load(os.path.join("Swinger", "pointer.png"))
#Sets a variable to know whether the scrpt has run once or not
FirstRun = 0
#Sets the variables to allow you to control movement
#Y axis movement Speed
MoveYSpeed = 0
#X axis movement speed
MoveXSpeed = 0
#Assigns the values later used to call the drawing
#of the player
PlayerPos = [255 += MoveXSpeed, 255 += MoveYSpeed]
#Assigns The first value of PlayerPos as a X axis value
PlayerPosX = PlayerPos[0]
#Assigns the second value of PlayerPos as a y axis value
PlayerPosY = PlayerPos[1]
它在第一个increment语句的第31行给出了一个语法错误,表示等号错误:

Traceback (most recent call last):
  File "...", line 31
    PlayerPos = [255 += MoveXSpeed, 255 += MoveYSpeed]
                      ^
SyntaxError: invalid syntax

我刚刚真正开始编写代码,很多代码可能没有达到正确的格式,我没有复制所有代码,因为我认为在到达任何其他代码之前出现错误可能与此无关。

PlayerPos=[255+=MoveXSpeed,255+=MoveYSpeed]
不是有效的Python语法,不,你想用那个表情做什么<代码>+=不是运算符,它是一条语句(如
=
赋值,或
返回
如果测试:
),不能将语句放在其他语句中

您的意思是仅仅使用
+
加法运算符吗

PlayerPos = [255 + MoveXSpeed, 255 + MoveYSpeed]

将创建一个以这两个和作为初始值的列表。

PlayerPos=[255+=MoveXSpeed,255+=MoveYSpeed]
不是有效的Python语法,不是。您想对该表达式做什么?我想能够通过一个单独的变量递增这些值。我使用pygame,我使用这两个值作为X和Y,所以我想在玩家持有某个键时通过移动速度变量来增加它们。。。事实上是这样。不能将值赋给整数。它已经代表了one@LPK:您也不能在表达式中使用语句<代码>+=是扩充赋值,一个语句。是。如果你能解释错误发生的原因,另一点就好了。你是在问他,而不是在描述那件事problem@LPK:嗯,问题中没有对预期结果的描述,因此这涉及到大量猜测。这个答案为时尚早,因为问题或问题中的代码没有整体逻辑。所有这些都不会对任何人有帮助,提问者说这并不是他真正想要的。如果这里的目标是有一个问题和答案来回答试图做x=y+=255这样的事情的人,那么这里所有多余的话题都应该被删掉。但这是一个严重的印刷错误,我认为整个事情应该结束。@dbliss:同意,post closed。