标签:全局变量 不能 java cti 数据 params key section ble
Python一些常见的错误总结如下:
AttributeError: type object ‘Fruits‘ has no attribute ‘get_discount‘,属性错误
if spam == 42 print(‘Hello!‘)
if spam = 42: print(‘Hello!‘)
print(‘Hello!‘)
print(‘Howdy!‘)
或者:
if spam == 42:
print(‘Hello!‘)
print(‘Howdy!‘)
或者:
if spam == 42:
print(‘Hello!‘)
spam = [‘cat‘, ‘dog‘, ‘mouse‘]
for i in range(spam):
print(spam[i])
spam = ‘I have a pet cat.‘
spam[13] = ‘r‘ print(spam)
而你实际想要这样做:
spam = ‘I have a pet cat.‘
spam = spam[:13] + ‘r‘ + spam[14:] print(spam)
numEggs = 12 print(‘I have ‘ + numEggs + ‘ eggs.‘)
而你实际想要这样做:
numEggs = 12 print(‘I have ‘ + str(numEggs) + ‘ eggs.‘)
或者:
numEggs = 12 print(‘I have %s eggs.‘ % (numEggs))
print(Hello!‘) 或者: print(‘Hello!)
或者:
myName = ‘Al‘ print(‘My name is ‘ + myName + . How are you?‘)
foobar = ‘Al‘ print(‘My name is ‘ + fooba)
或者:
spam = ruond(4.2)
或者:
spam = Round(4.2)
spam = ‘THIS IS IN LOWERCASE.‘
spam = spam.lowerr()
spam = [‘cat‘, ‘dog‘, ‘mouse‘]
print(spam[6])
spam = {‘cat‘: ‘Zophie‘, ‘dog‘: ‘Basil‘, ‘mouse‘: ‘Whiskers‘}
print(‘The name of my pet zebra is ‘ + spam[‘zebra‘])
class = ‘algebra‘
Python3的关键字有:and, as, assert, break, class, continue, def, del, elif, else, except, False, finally, for, from, global, if, import, in, is, lambda, None, nonlocal, not, or, pass, raise, return, True, try, while, with, yield
spam = 0
spam += 42
eggs += 42
someVar = 42
def myFunction():
print(someVar)
someVar = 100
myFunction()
spam = range(10)
spam[4] = -1
也许这才是你想做:
spam = list(range(10))
spam[4] = -1
(注意:在 Python 2 中 spam = range(10) 是能行的,因为在 Python 2 中 range() 返回的是list值,但是在 Python 3 中就会产生以上错误)
spam = 1
spam++
也许这才是你想做的:
spam = 1
spam += 1
class Foo(): def myMethod():
print(‘Hello!‘) a = Foo() a.myMethod()
标签:全局变量 不能 java cti 数据 params key section ble
原文地址:https://www.cnblogs.com/anthony-wang0228/p/10623543.html