6)测验测验连接非字符串值与字符串(导致 “TypeError: Can’t convert ‘int’ object to str implicitly”)
该缺点产生在如下代铝闼楹
- numEggs = 12
- print('I have ' + numEggs + ' eggs.')
而你实际想要如许做:
- numEggs = 12
- print('I have ' + str(numEggs) + ' eggs.')
或者:
7)在字符串首尾忘记加引号(导致“SyntaxError: EOL while scanning string literal”)
该缺点产生在如下代铝闼楹
- print(Hello!')
或者:
- print('Hello!)
或者:
- myName = 'Al'
- print('My name is ' + myName + . How are you?')
8)变量或者函数名拼写缺点(导致“NameError: name ‘fooba’ is not defined”)
该缺点产生在如下代铝闼楹
- foobar = 'Al'
- print('My name is ' + fooba)
14)在定义局部变量前在函数中应用局部变量(此时有与局部变量同名的全局变量存在)(导致“UnboundLocalError: local variable ‘foobar’ referenced before assignment”)
或者:
- spam = ruond(4.2)
或者:
- spam = Round(4.2)
9)办法名拼写缺点(导致 “AttributeError: ‘str’ object has no attribute ‘lowerr‘”)
该缺点产生在如下代铝闼楹
- spam = 'THIS IS IN LOWERCASE.'
- spam = spam.lowerr()
该缺点产生在如下代铝闼楹
- spam = ['cat', 'dog', 'mouse']
- print(spam[6])
11)应用不存在的字典键值(导致“KeyError:‘spam’”)
该缺点产生在如下代铝闼楹
- spam = {'cat': 'Zophie', 'dog': 'Basil', 'mouse': 'Whiskers'}
- print('The name of my pet zebra is ' + spam[
推荐阅读
我是如何在 SQL Server 中处理每天四亿三千万记录的?
开辟者大年夜赛路演 | 12月16日,技巧立异,北京不见不散 项目背景这个项目是请求做情况监控,我们暂且把受监控的设备称为采集设备,采集设备的属性称为监控指标。项目请求:体系支撑不少于>>>详细阅读
本文标题:17个新手常见Python运行时错误
地址:http://www.17bianji.com/lsqh/39584.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示