This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
面向对象 | |
可扩展性及可嵌入性(可以把python 嵌入C/C++ 程序,提供脚本功能) | |
可移植性(无需修改就可以在任和系统平台运行) | |
# SyntaxError: invalid syntax (经常会遇到的python语法错误的提示。) | |
1,安装可以按照官网一步一步安装。 | |
windows | |
2,环境变量 (编辑变量名Pash 的变量,在变量值最后面加上;C:\Python27)然后再运行。 | |
3,在终端输入python 就进入了交互式环境 | |
>>>100 + 222 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一、python文件类型 | |
1,(源代码)python 源代码的文件以'py'为扩展名,由python程序解释,不需要编译(常用) | |
2,(字节代码)python 源文件经编译后生成的扩展名为‘pyc’的文件; | |
编译方法: | |
import py_compile(py康普雷)模块 | |
py_compile.compile('1.py') | |
保存为2.py的文件,然后终端到绝对路径输入: python 2.py 目录里面就会多一个1.pyc的文件。 | |
3,(优化代码)经过优化的源文件,扩展名为“.pyo” | |
: python -O -m py_compile 1.py | |
终端运行以后会在目录多一个1.pyo的文件。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
案例: | |
(123和“123”一样吗?不一样,一个是整数值,加了双引号“”就是字符串类型表示为(str))(type() :参数) | |
示例: | |
>>>num="123" | |
>>>type(num) | |
<type ' str'> | |
python数据类型(数字、字符串、列表、元祖、字典) | |
1.数字类型又分为四种类型(整型、长整型、浮点型、复数型) | |
【整型】 | |
整型《表示为(int)》表示的范围-2,147,483,648到2,147,483,647 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(序列:) | |
1.列表、元祖和字符串都是序列。 | |
2.序列的两个主要特点是索引操作符和切片操作符。 | |
(索引操作符让我们可以从序列中抓取一个特定项目,切片操作符让我们能够获取序列的一个切片即一部分序列。) | |
索引符号是:[]....()....隔开符: : | |
序列的基本操作: | |
1.len(): 求序列(字符串)长度 | |
2.+: 连接2个序列(返回两个字符串拼接在一起的值) | |
3.*: 重复序列元素 (*5,就是重复输出五次dandan这个值所对应的字符串) | |
(可以灵活运用"#"*40,显示40个#出来。) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
列表 : ([]) {<type 'list'>} | |
1.list 是处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目。 | |
2.列表是可变类型的数据。(和元祖不可变类型,不同的用法) | |
3.列表的组成:用[] 表示列表,包含了多个以逗号(,)分隔开的数字,或字符串。 | |
如: | |
>>>List1=['Tom','David','Cat','张三'] | |
>>>List2=[1,2,3,4,5] | |
>>>List3=["str1","str2","str3","str4","str5"] (每个逗号分开的都是一个元素) | |
列表的定义: | |
>>>listdandan=[] (这是定义一个空列表) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
字典 (定义 {} 、 格式 (:) ) <type 'dict'> | |
字典是python中唯一的映射类型(哈希表) | |
字典的对象是可变的,但是字典的键必须使用不可变对象,并且一个字典中可以使用不同类型的键值。 | |
keys()或者values() 返回键列表或者值列表 | |
items() 返回包含键值对的元祖 | |
字典的定义:用花括号{} | |
>>> d={1:2,2:3,3:4} (定义一个字典d) | |
>>> type(d) (查看d 属于什么类型) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
浅拷贝和深拷贝 (milo) | |
1、浅拷贝:所谓浅拷贝就是对引用的拷贝 (只拷贝父对象) | |
2、深拷贝 : 所谓深拷贝就是对对象的资源的拷贝。 | |
列子: | |
>>> a=[1,2,3,'a','b','c'] (定义一个列表a) | |
>>> b=a (b 调用 a 的值,等于a和b是同一个列表了) | |
>>> b | |
[1, 2, 3, 'a', 'b', 'c'] | |
>>> a (a、b 叫变量、标签、对象都可以) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
条件判断: | |
1、判断再判断。 | |
2、猜数字 | |
################################################### | |
语法结构 : if (单个分支) else(和if 共同使用能建立多个分支,if 逻辑值解析为0或者空,false;用else 下的代码来执行,else不能独立使用) | |
if语句:if 语句包含一个逻辑表达式,使用表达式比较。在比较的结果的基础上做出决定。 | |
>>>if expression(条件表达式): 实现语句分支 (记住要以: 冒号结尾) | |
statement(s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1、for循环: | |
循环是一个结构,导致一个程序要重复一定次数,条件循环也是如此,当条件变为假False,循环结束。 | |
在python for循环遍历序列,如一个列表或一个字符。 | |
for循环语法: | |
迭代变量:iterating_var(a特ruzi停 窝儿) : 可以取任何数字或者英文,任何值做为迭代变量。 | |
for (迭代变量,可以巡检定义任何) in (序列:可以是一个值、变量、元祖、列表、字典等) |
OlderNewer