Python全栈工程师Day03学习笔记

来源:互联网 发布:财税律师知乎 编辑:程序博客网 时间:2024/06/05 22:32

PART 01

写在前面的话:

All grows is a leap in the dark.
所有的成长都是黑暗中的一跃!!!!

PART 02 Python历史、32/64-bit的区别、系统运行机制浅析

一. Python历史

  1. 1989年,Guido开始写Python语言的编辑器。
  2. 1991年,第一个Python编译器诞生。它是用C语言实现的,并能够调用C语言的库文件。
  3. Granddaddy of Python web frameworks, Zope 1 was released in 1999 .
  4. Python 2.0 - October 16 , 2000年 , 加入了内存回收机制,构成了现在Python语言框架的基础。
  5. Python 2.4 - November 30 , 2004年 , 经典版本,同年目前最流行的web框架Djanggo(D不发音)框架 。
  6. Python 2.7 - July 3 , 2010年 , 目前业内主流使用的工业版本依然是2.7 。
  7. In November 2014 , it was announced that Python 2.7 would be supported until 2020 , and reaffirmed that there would be no 2.8 release as users were expected to move to Python 3.4+ as soon as possible .
  8. Python 3.0 - December 3 , 2008 .

二. 32-bit/64-bit、系统运行机制浅析

  1. 32位:内存的最大寻址空间是2^32 , 即4GB 。 (说明:若硬件为8GB内存,但32位只支持到4GB内存)
  2. 64位:理论上,内存的最大寻址空间是2^64,但实际上支持不到这么大的内存,约为2^4x,即十几TB 。
  3. 目前主板支持的最大内存是100多GB 。
  4. 硬件为4GB内存,64位的系统与32位的系统一样快。
  5. 操作系统也需要占用一定的内存。
  6. 对一台计算机的性能进行分析,最主要的三个因素:CPU、Memory(内存)、Disk(硬盘)。内存与运行速度有关,而加载速度与硬盘有关。一个软件的运行:CPU通过OS(操作系统)的接口访问硬盘,从硬盘将数据读取到Memory中进行运行。
  7. 硬盘:5400转=骑自行车;7200转=骑电动车;10000转=骑快速电动车;15000转=骑摩托车(机械硬盘中最快的) | SSD=Tesla

PART 03 Python版本的选择

一. What are the differences?

Short version: Python 2.x is legacy(遗产), Python 3.x is the present and future of the language

Guido van Rossum (the original creator of the Python language) decided to clean up Python 2.x properly(适当的), with less regard(不管) for backwards compatibility(兼容) than is the case for new releases in the 2.x range. The most drastic(激进的) improvement is the better Unicode(一个编码,支持中文:在Python2.x上,默认编码为ASSIC,不支持中文 | 在Python3.x上,默认编码为UNICODE) support (with all text strings being Unicode by default) as well as saner bytes/Unicode separation(分离).

Besides, several(几个) aspects(方面) of the core(核心) language (such as print and exec being statements, integers using floor division) have been adjusted to be easier for newcomers to learn and to be more consistent(持续的) with the rest of the language, and old cruft has been removed (for example, all classes are now new-style, “range()” returns a memory efficient iterable, not a list as in 2.x).

What’s New in Python 3.0 document provides a good overview of the major language changes and likely sources of incompatibility with existing Python 2.x code. Nick Coghlan (one of the CPython core developers) has also created a relatively extensive FAQ regarding the transition.

However, the broader Python ecosystem has amassed a significant amount of quality software over the years. The downside of breaking backwards compatibility in 3.x is that some of that software (especially in-house software in companies) still doesn’t work on 3.x yet.

二. Python3.0 vs Python2.x总结:

① 默认支持中文
② 不兼容2.x
③ 核心语法 的调整,更易学习
④ 新特性默认只在3.x版本上支持

PART 04 第一个Python程序

Python官方下载地址
Notepad++官方下载地址
shadowsocks开源地址

一. Python 的交互器模式

print("Hello world")

Python的交互器模式-第一个Python代码
缺点:文件不能永久保存,主要用于简单的语法测试

二. 命令行方式

命令行方式-Python的第一行代码

PART 05 文件后缀及系统环境变量介绍

一. 命令行命令

命令 作用 d: 切换盘符 dir 查看当前目录文件 cd 进入目录 tab 命令行自动补全 cd .. 返回上级目录 cd ../.. 返回两层上级目录 notepad 记事本 shutdown 60秒关机倒计时 calc 计算器 explorer 资源管理器 logoff 注销 cls 清空DOS界面 ver 查看系统版本号 exit 退出DOS界面 taskmgr 任务管理器 osk 系统屏幕键盘 ipconfig 本机IP配置

二. 文件扩展名

.py ……python文件

三. 环境变量

  1. 在Path属性中修改变量值:每个路径用“ ”区分。
  2. 添加Python可执行文件.exe所在目录路径到Path属性中即可,也可以在Python安装时勾选自动添加Python到Path。
  3. 输入Python出现版本信息即配置成功。
    Python的Path添加验证界面

PART 06 Python程序文件执行与其他编程语言的简单对比

  1. Python在Windows平台上是默认没有的,需要自己安装,而在Linux、Mac、Unix系统上是默认就有的,不需要再下载安装。
  2. 执行.Py程序的方式有两种:交互器模式和文件执行。
  3. 对比其他语言的“hello world”(略)[C、C++、Java、Php、Ruby、Go],Python与Ruby很像。

PART 07 变量详解

一.变量

  1. Variables(变量) are used to store(保存、储存) information to be referenced(被调用) and manipulated(操作或更改) in a computer program. They also provide a way of labeling(标记) data with a descriptive(描述性) name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers(容器) that hold information(如果我们把变量看作成是一个保存信息的容器是更容易理解的). Their sole(主要) purpose(目的) is to label(标记) and store(存储) data in memory. This data can then be used throughout(整个) your program.
  2. 变量的作用:是为了存储程序运算过程中的一些中间结果的,为了方便日后调用(存储在内存中)。

二.命名与写法

  1. 变量的两种写法 : ① 驼峰体( eg. studentNumberHxx ) ② 下划线( eg. student_number )
  2. 变量的命名规则
    1. 要具有描述性
    2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)
    3. 不能以中文为变量名
    4. 不能以数字开头
    5. 保留字符是不能被使用[‘and’, ‘as’, ‘assert’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘exec’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘not’, ‘or’, ‘pass’, ‘print’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]

三. 常量

  1. 常量:不变的量 PIE = 3.141592653….
  2. 在Python里面所有的变量都是可变的 ,即不区分常量与变量,所以用全部大写的变量名来代表次变量为常量。

四. 变量的赋值

name = "Alex Li"name2 = nameprint(name,name2)  name = "Jack"print("What is the value of name2 now?") 

变量赋值

五. 内存回收机制
1. Python的内存是自动回收的,即如果没有变量指向,则该块内存被自动回收。
2. 内存的回收方法

age = 21print(age)del age # 方法一为del手动释放,此时21所在的内存块被回收,再次打印age时报错
age = 22age = 24 # 方法二为重新指向24所在内存,此时22所在内存块被回收

内存回收机制

原创粉丝点击