python end of statement_17个新手常见Python运行时错误
12) Trying to use a Python keyword for a variable name. (Causes “SyntaxError: invalid syntax”)
The Python keywords (also called reserved words) cannot be used for variable names. This happens with code like:
class = 'algebra'
The Python 3 keywords are: 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
13) Using an augmented assignment operator on a new variable. (Causes “NameError: name 'foobar' is not defined”)
Do not assume that variables start off with a value such as 0 or the blank string. A statement with an augmented operator like spam += 1 is equivalent to spam = spam + 1. This means that there must be a value in spam to begin with.
This error happens with code like this:
spam = 0
spam += 42
eggs += 42
14) Using a local variable (with the same name as a global variable) in a function before assigning the local variable. (Causes “UnboundLocalError: local variable 'foobar' referenced before assignment”)
Using a local variable in a function that has the same name as a global variable is tricky. The rule is: if a variable in a function is ever assigned something, it is always a local variable when used inside that function. Otherwise, it is the global variable inside that function.
This means you cannot use it as a global variable in the function before assigning it.
This error happens with code like this:
someVar = 42
def myFunction():
print(someVar)
someVar = 100
myFunction()
python end of statement_17个新手常见Python运行时错误相关推荐
- python invalid type promotion_17个新手常见Python运行时错误
当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif, else, for, wh ...
- python错误-新手常见Python错误及异常解决处理方案
写Python代码的小伙伴不可避免地会遇到代码执行错误和异常,这次就来详细且不失通俗地总结一下python中的错误和异常. 先抛出两个问题: 什么是Python错误和异常? 如何处理Python错误和 ...
- 怎么解决python遇到问题_新手常见Python错误及异常解决处理方案
新手常见Python错误及异常解决处理方案,异常,错误,语句,子句,代码 新手常见Python错误及异常解决处理方案 易采站长站,站长之家为您整理了新手常见Python错误及异常解决处理方案的相关内容 ...
- python not in range1002无标题_17个新手常见Python运行时错误
学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif , else , for , w ...
- python--17个新手常见Python运行时错误
当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif , else , for , ...
- python定义函数名typo错误_17个新手常见Python运行时错误
当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在if,elif,else,for,while,cl ...
- python中常见的运行时错误_python--17个新手常见Python运行时错误
当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif, else, for, wh ...
- python学起来难不难-新手学python数据分析难不难?
原标题:新手学python数据分析难不难? 有很多没有基础的新手想学习python数据分析,却在纠结python数据分析难不难学?下面容妹给大家整理了资料,为各位分享! 1.python难不难? Py ...
- python手写代码面试_常见Python面试题—手写代码系列
原标题:常见Python面试题-手写代码系列 1.如何反向迭代一个序列 #如果是一个list,最快的方法使用reverse tempList = [1,2,3,4] tempList.reverse( ...
最新文章
- 理解class.forName()(good--字节码层面)
- ASP.NET MVC 随笔汇总
- 我的新书《Java编程讲义》新鲜出炉啦,欢迎订阅
- 如何在Python中针对一个值检查多个变量?
- linux mysql5.7.18多实例_mysql5.7.13二进制包安装多实例
- Linux 启动顺序
- 《统计学习方法》的Python 3.6复现,实测可用
- android 实现代码混淆
- arch终端添加中文支持_arch/manjaro - 添加archlinuxcn的软件源
- 2016年不容错过的十五大智能家居产品
- OO第一单元总结——求导之旅
- 第2章 系统的分层结构
- moxa串口卡Linux驱动,moxa多串口驱动下载
- 计算机电子表格相关简答题,2017年计算机一级excel操作试题及答案
- STM32CubeMX工程提示未定义变量LL_APB1_GRP1_PERIPH_BKP
- LCD显示屏和OLED显示屏的区别
- [已解决]你的支付授权失败。请核对你的信息并重试,或尝试其他支付方式。请联系你的银行了解更多信息
- 第三方App接入微信登录 解读 (微信开放平台)
- 被评为“影响世界千年的物理学家”,杨振宁的伟大,你根本不了解
- [每日100问][2011-9-06]iphone开发笔记,今天你肿了么
热门文章
- python入门:Anaconda和Jupyter notebook的安装与使用
- oracle格式化列宽度,ORACLE日期时间的格式化参数大全
- SystemC 代码添加和测试方法
- matlab 绘制符号函数,DAY8 MATLAB学习笔记—simulink入门、MATLAB符号函数的图形绘制...
- python生成1到100的列表_python列表生成式与列表生成器的使用
- cmd运行python程序
- azul java_Java版本更新重大提醒 - Azul
- 测试开发——搭建一个简单 web服务(flask框架基础)项目实战
- 2016年3月13日02:03:53
- IOS-NSDateFormatter使用介绍