小编Ped*_*ian的帖子

三重引用字符串的串联

我目前正在尝试使用变量在三引号字符串中连接.最好的方法是什么?

print('''
Points left to spend: ''' + str(pointsLeft) + '''
''' + str(attrChoice) + ':\t' + '''[''' + str(charAttr[attrChoice]) + ''']
To reduce the number of points spent on this skill, simply enter a negative number.
'''
)
Run Code Online (Sandbox Code Playgroud)

我得到的错误消息是:关键字不能是表达式.任何人都可以解释这意味着什么,以及是否有可能尝试这样的连接?

python concatenation syntax-error string-interpolation

2
推荐指数
1
解决办法
2349
查看次数

为什么空格被视为语法错误?

我正在使用Python 3.1 IDLE并且发现空格(我将这样标记为_)被IDLE强调为语法错误.我想知道是否有人知道问题所在并提供解决方案.我知道它看起来不对,但下划线就是要强调IDLE说问题所在.我无法弄清楚该行和下一行的问题是什么.

    def attrSelection():
        while attrChoice!=6
            if attrChoice==1:
                attrChoice=Power
                baseAttr=int(basePow)
                attrEditor()
     _      elif attrChoice==2:
                attrChoice=Health
                baseAttr=int(baseHlth)
                attrEditor()
            elif attrChoice==3
                attrChoice=Wisdom
                baseAttr=int(baseWis)
                attrEditor()
            elif attrChoice==4:
                attrChoice=Dexterity
                baseAttr=int(baseDex)
                attrEditor()
            elif attrChoice==5:
                assignRandom()
            else:
                print('Option does not exist.  Please enter option in range 1-6.')
                attrChoice=input('Choice: ')
Run Code Online (Sandbox Code Playgroud)

python syntax-error

1
推荐指数
1
解决办法
943
查看次数