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()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/574977.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android Fragment功能的例子

实现的功能很简单,也是最基本的,上下分别是两个Fragment,上面的Fragment中是一个listview,当点击item时,下面的Fragment显示对应的文字详细信息 具体的实现步骤如下:①创建工程FragmentExam,目录…

java上传图片http错误_上传图片出错

源码:package action;import java.io.IOException;import com.qiniu.common.QiniuException;import com.qiniu.http.Client;import com.qiniu.http.Response;import com.qiniu.storage.UploadManager;import com.qiniu.util.Auth;public class UploadAction {public…

template标签_C++核心准则T.65:使用标签分发提供函数的不同实现

T.65: Use tag dispatch to provide alternative implementations of a functionT.65:使用标签分发提供函数的不同实现Reason(原因)A template defines a general interface.模板定义普遍接口。Tag dispatch allows us to select implementations based on specific properties…

Windows服务器学习篇:服务器连接与退出

此文是我早期在公司内部发布的一篇给予新入职程序员基础技术培训的文章,非常基础简单,现拿出来给大家分享。当然,已工作人士可直接忽略... 一、Windows服务器连接 1. 在桌面菜单中的“运行”里,输入mstsc命令,然后回车…

nginx动静分离配置_Nginx动静分离

动静分离动静分离,就是将JSP、Servlet等动态资源交由Tomcat或其他Web服务器处理,将CSS、js、image等静态资源交由Nginx或其他Http服务器处理,充分发挥各自的优势,减轻其他服务器的压力,搭建更为高效的系统架构。Nginx动…

用java自动化访问百度测试_java+eclipse+selenium+百度搜索设置自动化测试

在eclipse中新建一个项目baidutest;再在src文件夹中新建一个包com.baidutest.homework;再在包中新建一个java类baidusetting,并设置为静态类;最后在项目中新建一个lib文件夹,将selenium的所有架包拷贝到lib文件夹中&am…

内存泄漏以及常见的解决方法

之所以撰写这篇文章是由于前段时间花费了非常大的精力在已经成熟的代码上再去处理memory leak问题。写此的目的是希望我们应该养成良好的编码习惯,尽可能的避免这种问题,由于当你对着一大片的代码再去处理此类的问题,此时无疑添加了解决的成本…

python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜实例代码

首先找到要下载的歌曲排行榜的链接,这里用的是:https://music.163.com/discover/toplist?id3778678然后更改你要保存的目录,目录要先建立好文件夹,例如我的是保存在D盘-360下载-网易云热歌榜文件夹内,就可以完成下载。…

java thread 名称_Thread类常用方法之设置线程名称

package com.itheima.demo02.setName;/*设置线程的名称:(了解)1.使用Thread类中的方法setName(名字)void setName(String name) 改变线程名称,使之与参数 name 相同。2.创建一个带参数的构造方法,参数传递线程的名称;调用父类的带参构造方法,把线程名称传递给父类,让…

HDU 1108 最小公倍数

最小公倍数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32794 Accepted Submission(s): 18303Problem Description给定两个正整数,计算这两个数的最小公倍数。Input输入包括多组測试数据&#…

Java为xml跟节点添加子节点_如何将xml节点作为第一个子节点插入Java中的另一个xml文档中?...

小编典典如果事实证明我只是为您做功课,我会感到非常恼火。package com.akonizo.examples;import java.io.ByteArrayInputStream;import java.io.StringWriter;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import j…

成员变量和局部变量的区别_Java 变量类型

点击上方“蓝字”带你去看小星星今天主要学习Java变量类型,主要是局部变量、实例变量和类变量(静态变量)。Java语言中,所有的变量在使用前必须声明。声明变量的基本格式如下:type identifier [ value][, identifier [ value] ...] ;格式说明…

java gson序列化_java – Gson多态序列化

使用Gson 2.2.2我正在尝试序列化POJO(行为)的数组列表.我有一个适配器几乎是我在网上看到的副本:public class BehaviorAdapter implements JsonSerializer {private static final String CLASSNAME "CLASSNAME";private static final String INSTANCE …

【云图】如何制作附近实体店的地图?-微信微博支付宝

【云图】如何制作附近实体店的地图?-微信微博支付宝 原文:【云图】如何制作附近实体店的地图?-微信微博支付宝 摘要: 附近连锁店地图与全国连锁店地图,最大的区别就是: 1、附近连锁店地图需要先定位,然后搜…

php curl跨域cookie_PHP curl模拟文件上传(接口请求实现跨域文件中转)

3e2f08c0c11a8416dd107bbfc9159718.jpg客户端代码请求参数参数类型参数说明$urlstringpost提交的服务器url路径$data数组表单数据$files数组表单文件public function curl_custon_postfields($url, array $data array(), array $files array()){$curlfiles array();foreach …

oracle 分页_80分页查询,不止写法

据孔老先生说,茴香豆的茴字有四种写法,那oracle的分页查询又有多少种写法呢?分页查询,其实本质上就是topN查询的变种, 如果把topN的一部分结果集去掉,就变成了分页.topN的基本写法,两层select,第一层先order by,第二层再用rownum:select owner,object_name,object_id,rownum a…

笔记:Hadoop权威指南 第1章 初识Hadoop

大数据处理遇到问题: (1)、磁盘存储容量快速增加,但是访问速度进步不大;用户乐意使用磁盘共享访问。 (2)、硬件故障,可以使用备份解决。 (3)、分布式系统,需要可靠性。 关系数据库与MapReduce比较: (1)、磁…

php switch if,php switch 与 if else 区别

在php中switch是选择,if else也有同理,但是它们肯定是有区别的,那么我们来看看它们两者的区别在哪里呢,下面先看switch case语句吧。switch($id){case 1:return asp/;break;case 2:return phper/;break;case 3:return jsp/;break;…

python读取mat数据是字典形式如何转化为矩阵_mat2json, python读取mat成字典, 保存json...

python程序, 实现matlab的.mat格式转化为dict / json .第一个参数mat_path代表需要转化的mat路径;第二个参数, 如果需要把字典序列化成json, 添加这一参数, 代表json存放位置;返回值: 转化好的字典import osimport jsonimport scipy.io as spioimport pandas as pddef loadmat(…

GitHub上创建组织

4.3. 组织和团队 GitHub 在早期没有专门为组织提供账号,很多企业用户或大型开源组织只好使用普通用户账号作为组织的共享账号来使用。后来,GitHub推出了组织这一新的账号管理模式,满足大型开发团队的需要。 组织账号是不能用来登录的&#xf…