首页 > 编程语言 >Python学习day01

Python学习day01

时间:2023-01-04 09:44:12浏览次数:43  
标签:编码 .. 文件 Python day01 默认 学习 --

一、python介绍

 

①发展史
被解救的姜戈
2.4 50万行
Python 2.6 - October 1, 2008
Python 2.6.1 - October 1, 2008
Python 2.6.6 - October 1, 2008
Python 3.0 - December 3, 2008
Python 2.7 - July 3, 2010 #目前业内主流使用的工业版本依然是2.7

print "hello world" #in 2.x
print("hello world") #in 3.x


In summary : Python 2.x is legacy, Python 3.x is the present and future of the language

总结: python2.x 是遗产, python3.x是现在和未来的语言

Python 3.0 was released发布 in 2008. The final最终 2.x version 2.7 release came out in mid-2010,
with a statement声明 of extended延长 support支持 for this end-of-life release. The 2.x branch分支 will see no new major重大 releases after that.
3.x is under active development 正在活跃的开发 and has already已经 seen有了 over超过 five years of stable稳定的 releases版本, including包括 version版本 3.3 in 2012,

 

3.4 in 2014, and 3.5 in 2015. This means意味着 that all recent近期的 standard标准的 library库 improvements升级/改进, for example例子, are only

 

available可用的 by default默认 in Python 3.x.

 

2.x = 默认编码 =ASSIC =不支持
3.x = 默认编码 =UNICODE =默认支持中文

 

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(是一个编码)中文支持 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)

 

python 2 vs 3
1。 默认支持中文
2. 不兼容2.x
3. 核心语法调整,更易学
4. 新特性默认只在3.x上有

 

 

②系统位数

32bit =内存的最大寻址空间是2**32, 4GB
64bit, =2**64 但实际上支持不到这莫大的内存,2**4x, 目前主板支持的最大的内存是100多GB


4gb ==64位系统 会不会比32位系统快? = 一样的

硬盘:
5400转 = 每分钟 =骑自行车
7200转 = 每分钟 =骑电动车
10000转 = 每分钟 =骑快速电动车
15000转 = 每分钟 =骑摩托车 机械硬盘最快的

SSD = Tesla

Python 2 or 3?
安装
交互器模式

开始--》cmd --> cd c:\ -->dir
cd = change directory
dir = 查看当前目录文件列表


cd .. 返回上一层目录
cd ../.. 返回上上一层目录
cd ../../.. 返回上上上一层目录
cd ../../../.. 返回上上上上一层目录


D:\>"d:\Program Files\Python35\python.exe" c:\hello.txt
Hello World!


#c:\hello.txt .txt 代表文件的扩展名(后缀名),用于区分文件类型
.txt 记事本文本文件
.doc word文件
.xls excel文件
.ppt PPT文件
.exe 可执行文件
.jpg .png .jpeg 图片
.gif 动态图片
.pdf PDF文件
.mp4 .avi 视频
.py python文件
.java java 文件
.c .h c源码
.php php文件
.js javascript

 

③环境变量
D:\Program Files\Python35\Scripts\;
D:\ProgramFiles\Python35\;
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
D:\Program Files\Python27

执行py程序方式为:
1. 交互器,缺点程序不能永久保存,主要用与简单的语法测试相关
2. 文件执行

二、hello world
Hello World程序
变量
变量 是 为了存储 程序运算过程中的一些中间 结果,为了方便日后调用

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.

 

④变量的命名规则
1. 要具有描述性
2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)
3. 不能以中文为变量名
4. 不能以数字开头
5. 保留字符是不能被使用

常量 :不变的量 pie = 3.141592653....
在py里面所有的变量都是可变的 ,所以用全部大写的变量名来代表次变量为常量



⑤字符编码
支持中文的第一张表就叫 GB2312
1980 gb2312 6700+
1995 gbk1.0 20000
2000 gb18030 27000
big5 台湾

unicode 万国码 支持所有国家和地区的编码
2**16 = 65535 = 存一个字符 统一占用2个字节


UTF-8 = unicode 的扩展集,可变长的字符编码集

Assic -->Gb2312 ->gbk1.0-->gb18030
Assic -->unicode -->utf-8 /utf-16


Python2.x == Assic 默认编码
#!-*- coding:utf-8 -*-
#coding:utf-8

python3.x == unicode默认编码


unicode 是向下兼容gb2312 , gbk


⑥注释
单行注释 用#
多行注释用三个单引号或三个双引号 '''被注释的内容'''

⑦表达式if ...else语句
    缩进 IndentationError: expected an indented block
                                ^
    IndentationError: unindent does not match any outer indentation level
    SyntaxError: invalid syntax 语法错误
    tab != 4个空格
    
    缩进级别必须保持一致

 

标签:编码,..,文件,Python,day01,默认,学习,--
From: https://www.cnblogs.com/caosongsong/p/17023997.html

相关文章

  • PostgreSQL citus python环境搭建
    PostgreSQLcituspython环境搭建 精选 原创Janeh10182022-01-0809:19:09博主文章分类:PostgreSQL©著作权文章标签sqlpostgresql数据库文章分类其它数据库阅读数27......
  • Python 数据类型详细篇:字符串
    Python基本数据类型中的字符串类型,字符串类型在实际的开发中是一个经常会用到的数据类型,比较重要。下面我们一起来看一下:1.简介字符串类型的数据表示一段文本,使用单引号......
  • stl学习之rope
    简介rope是本人在极度不想敲平衡树的情况下从朋友偶然听说的,了解之后用寥寥数行边秒杀了那道平衡树的题。笔者遂深感其强大与低调,故写笔记以纪念之。头文件与定义#inclu......
  • Spring IOC官方文档学习笔记(六)之自定义bean的特性
    1.生命周期回调(1)如果我们想要介入bean的生命周期,可通过实现spring中的InitializingBean和DisposableBean接口来达到这一目的,spring会调用InitializingBean中的afterPro......
  • 《STL 源码剖析》学习笔记之容器(二)list
    [图]Theorange 2019-08-061、list概述相较于vector的连续线性空间,list就显得复杂许多,它的好处是每次安插或删除一个元素,就配置或释放一个元素空间。因此,list对于空间......
  • 从零开始学习 MySQL 系列--索引、视图、导入和导出
    前言上篇文章我们学习了数据库和数据表操作语句,今天我们学习下数据库索引,视图,导入和导出的知识。作为基础篇,不会涉及到关于索引和视图的高级应用和核心概念,但是基本操作大家......
  • Python转义字符理解
    #Author:符攀飞#Blog:feifeige.top#Date:2023/1/322:09#File:day02.py#转义字符print('hello\nworld')#\n换行print('hello\tworld')#t占四个,hello多......
  • 用Python批量绘制二维矩阵
    importnumpyasnpfrommatplotlibimportpyplotaspltimportmatplotlibasmplimportglobdefcreate_4_colorMap():#colors=['blue','cyan','green','p......
  • 「AcWing学习记录」区间问题
    AcWing905.区间选点原题链接给定N个闭区间[ai,bi],请你在数轴上选择尽量少的点,使得每个区间内至少包含一个选出的点。输出选择的点的最小数量。位于区间端点上的点......
  • 创建python虚拟环境
    安装pipinstallvirtualenvcd到指定目录virtualenv目录名--python==python3.7 ---如何激活python进入scripts目录,执行该文件   ---给虚拟环境安装dj......