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 命令行编辑功能. 为源文件指定不同的编码: #…
6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知的脚本文件. 随着编程的深入,代码的增多,你可能又会将代码存到不同的文件中方便管理. 你会想到去使用之前的编程中已经写好了的一个函数的定义. Python有自己的方式去实现这些.它会将这些保存了定义的函数,类等的文件(文件夹)称作module; 一个module中的定义的函数 类等可以被导入到另一个…
笔记-python -asynio 1.      简介 asyncio是做什么的? asyncio is a library to write concurrent code using the async/await syntax. asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers,…
笔记-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.…
笔记-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. 两个命名空间中的名称之间没有任何关系,例如两个模块可以都定义一…
[译]The Python Tutorial#Data Structures 5.1 Data Structures 本章节详细介绍之前介绍过的一些内容,并且也会介绍一些新的内容. 5.1 More on Lists 列表数据类型拥有更多方法,以下是列表对象的所有方法: list.append(x) 在列表末尾添加新项,等同于a[len(a):] = [x] list.extend(iterable) 添加可迭代对象中所有的项来扩展列表,等同于a[len(a):] = iterable list…
[译]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…
[译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使用文本编辑器来准备解释器的输入会更好,使用文件作为替代的输入.这也被称作创建脚本.当程序越来越长时,出于易于维护的原因,你可能会将程序分割为几个文件.你也可能想要在多个程序中使用很好用的一个函数,而不用将其定义拷贝到每一个程序中. 为了支持这些需求,Python提供了将定义放入一个文件的方式,并且在…
写在前面 本篇文章是<The Python Tutorial>(3.6.1),第九章,类的译文. 9. Classes 与其他编程语言相比,Python的类机制定义类时,最小化了新的语法和语义的引入.Python类机制是C++和Modula-3的混合体.Python类支持所有面向对象编程的特性: 类继承机制允许多继承,子类可以覆盖其父类们的任何方法,方法可以使用相同的名字调用父类中的方法.对象可以包含任意数量和类型的数据. 跟模块相似,Python类也具有Python的动态性质: 类在运行时被…
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…