1
)
尝试连接非字符串值与字符串(导致
“
TypeError:
Can’t
convert
‘int’
object to str implicitly
”)
该错误发生在如下代码中:
numEggs = 12print('I have ' + numEggs + ' eggs.')
而你实际想要这样做:
numEggs = 12print('I have ' + str(numEggs) + ' eggs.')
或者:
numEggs = 12print('I have %s eggs.' % (numEggs))
2
)
在字符串首尾忘记加引号(导致“
SyntaxError:
EOL
while
scanning
string
literal
”)
该错误发生在如下代码中:
print(Hello!')
或者
:
print('Hello!)
或者
:
myName = 'Al'print('My name is ' + myName + . How are you?')