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运行时错误相关推荐

  1. python invalid type promotion_17个新手常见Python运行时错误

    当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif, else, for, wh ...

  2. python错误-新手常见Python错误及异常解决处理方案

    写Python代码的小伙伴不可避免地会遇到代码执行错误和异常,这次就来详细且不失通俗地总结一下python中的错误和异常. 先抛出两个问题: 什么是Python错误和异常? 如何处理Python错误和 ...

  3. 怎么解决python遇到问题_新手常见Python错误及异常解决处理方案

    新手常见Python错误及异常解决处理方案,异常,错误,语句,子句,代码 新手常见Python错误及异常解决处理方案 易采站长站,站长之家为您整理了新手常见Python错误及异常解决处理方案的相关内容 ...

  4. python not in range1002无标题_17个新手常见Python运行时错误

    学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif , else , for , w ...

  5. python--17个新手常见Python运行时错误

    当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif , else , for , ...

  6. python定义函数名typo错误_17个新手常见Python运行时错误

    当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在if,elif,else,for,while,cl ...

  7. python中常见的运行时错误_python--17个新手常见Python运行时错误

    当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif, else, for, wh ...

  8. python学起来难不难-新手学python数据分析难不难?

    原标题:新手学python数据分析难不难? 有很多没有基础的新手想学习python数据分析,却在纠结python数据分析难不难学?下面容妹给大家整理了资料,为各位分享! 1.python难不难? Py ...

  9. python手写代码面试_常见Python面试题—手写代码系列

    原标题:常见Python面试题-手写代码系列 1.如何反向迭代一个序列 #如果是一个list,最快的方法使用reverse tempList = [1,2,3,4] tempList.reverse( ...

最新文章

  1. 理解class.forName()(good--字节码层面)
  2. ASP.NET MVC 随笔汇总
  3. 我的新书《Java编程讲义》新鲜出炉啦,欢迎订阅
  4. 如何在Python中针对一个值检查多个变量?
  5. linux mysql5.7.18多实例_mysql5.7.13二进制包安装多实例
  6. Linux 启动顺序
  7. 《统计学习方法》的Python 3.6复现,实测可用
  8. android 实现代码混淆
  9. arch终端添加中文支持_arch/manjaro - 添加archlinuxcn的软件源
  10. 2016年不容错过的十五大智能家居产品
  11. OO第一单元总结——求导之旅
  12. 第2章 系统的分层结构
  13. moxa串口卡Linux驱动,moxa多串口驱动下载
  14. 计算机电子表格相关简答题,2017年计算机一级excel操作试题及答案
  15. STM32CubeMX工程提示未定义变量LL_APB1_GRP1_PERIPH_BKP
  16. LCD显示屏和OLED显示屏的区别
  17. [已解决]你的支付授权失败。请核对你的信息并重试,或尝试其他支付方式。请联系你的银行了解更多信息
  18. 第三方App接入微信登录 解读 (微信开放平台)
  19. 被评为“影响世界千年的物理学家”,杨振宁的伟大,你根本不了解
  20. [每日100问][2011-9-06]iphone开发笔记,今天你肿了么

热门文章

  1. python入门:Anaconda和Jupyter notebook的安装与使用
  2. oracle格式化列宽度,ORACLE日期时间的格式化参数大全
  3. SystemC 代码添加和测试方法
  4. matlab 绘制符号函数,DAY8 MATLAB学习笔记—simulink入门、MATLAB符号函数的图形绘制...
  5. python生成1到100的列表_python列表生成式与列表生成器的使用
  6. cmd运行python程序
  7. azul java_Java版本更新重大提醒 - Azul
  8. 测试开发——搭建一个简单 web服务(flask框架基础)项目实战
  9. 2016年3月13日02:03:53
  10. IOS-NSDateFormatter使用介绍