笔记-python tutorial-9.classes】的更多相关文章

写在前面 本篇文章是<The Python Tutorial>(3.6.1),第九章,类的译文. 9. Classes 与其他编程语言相比,Python的类机制定义类时,最小化了新的语法和语义的引入.Python类机制是C++和Modula-3的混合体.Python类支持所有面向对象编程的特性: 类继承机制允许多继承,子类可以覆盖其父类们的任何方法,方法可以使用相同的名字调用父类中的方法.对象可以包含任意数量和类型的数据. 跟模块相似,Python类也具有Python的动态性质: 类在运行时被…
笔记-python tutorial-9.classes 1.      Classes 1.1.    scopes and namespaces namespace: A namespace is a mapping from names to objects. 典型的命名空间有:built-in names;the global names in a module; the local names in a function. 两个命名空间中的名称之间没有任何关系,例如两个模块可以都定义一…
Python Tutorial笔记 Python入门指南 中文版及官方英文链接: Python入门指南 (3.5.2) http://www.pythondoc.com/pythontutorial3/ Python Tutorial (3.5.2) https://docs.python.org/3/tutorial/ 2.使用Python解释器 Control-D 文件结束符,让解释器以0状态码退出,相当于exit()命令. Control-P 命令行编辑功能. 为源文件指定不同的编码: #…
笔记-python lib-pymongo 1.      开始 pymongo是python版的连接库,最新版为3.7.2. 文档地址:https://pypi.org/project/pymongo/ 使用文档:http://api.mongodb.com/python/current/tutorial.html The PyMongo distribution contains tools for interacting with MongoDB database from Python.…
[译]The Python Tutorial#Errors and Exceptions 到现在为止都没有过多介绍错误信息,但是已经在一些示例中使用过错误信息.Python至少有两种类型的错误:语法错误以及异常 8.1 Syntax Errors 语法错误,也称解析错误,是Python初学者经常抱怨的问题. >>> while True print('Hello world') File "<stdin>", line 1 while True print…
[译]The Python Tutorial#More Control Flow Tools 除了刚才介绍的while语句之外,Python也从其他语言借鉴了其他流程控制语句,并做了相应改变. 4.1 if Statements 或许最广为人知的语句就是if语句了.例如: x = int(input("Please enter an integer: ")) if x < 0: x = 0 print('Negative changed to zero') elif x == 0…
I have planed to learn Python for many times. I have started to learn Python for many times . However, I can't use it fluently up to now. Now I know I was wrong. I just tried to remember the syntax and took notes on paper with little practice. Now I…
Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一路跟着例程走过来的,你就会发现一下错误信息.在Python里面至少有两类错误:语法错误和异常(syntax errors and exceptions) 8.1. Syntax Errors 语法错误 语法错误就是语法错误,语法错误就是语法错误. 比如说,关键词拼写错误,缩进错误,标点符号错误等等,…
6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知的脚本文件. 随着编程的深入,代码的增多,你可能又会将代码存到不同的文件中方便管理. 你会想到去使用之前的编程中已经写好了的一个函数的定义. Python有自己的方式去实现这些.它会将这些保存了定义的函数,类等的文件(文件夹)称作module; 一个module中的定义的函数 类等可以被导入到另一个…
笔记-python操作mysql 1.      开始 1.1.    环境准备-mysql create database db_python; use db_python; create table `t2`( `id` int unsigned auto_increment, `name` varchar(30), primary key(`id`)); #创建用户并授权 create user 'dev_python' identified by '123456'; grant all…