1.格式化输入
>>> '%s %d-%d' % ('hello', 7, 1)
...'hello 7-1'
2.模块初识 标准库 第三方库
Python 提供了一个办法,把这些定义存放在文件中,为一些脚本或者交互式的解释器实例使用,这个文件被称为模块.
模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py。
模块可以被别的程序引入,以使用该模块中的函数等功能。这也是使用 python 标准库的方法。
3.sys os 模块
4.如何自己书写模块
5. .pyc
6.数据初识
type()
数字整数
浮点数
复数
布尔值
bytes
7.三元运算
a = 1 b = 2 c = 3 d = a if (a>b) else c
8.二进制与字符编码的转换
encode
decode
>>> 'erc'.encode('utf-8')
b'erc'
>>> 'erc'.encode()
b'erc'
>>> b'erc'.decode()
'erc'
9.列表及其相关运算操作
列表用中括号表示[ ]

1 >>> number = [1,2,3,4]
2 >>> number
3 [1, 2, 3, 4]
4 >>> number2= [1,2,3,]
5 >>> number
6 [1, 2, 3, 4]
7 >>> number2
8 [1, 2, 3]
9 >>> number[0]
10 1
11 >>> number[:]
12 [1, 2, 3, 4]
13 >>> number[1:2]
14 [2]
15 >>> number[-2:]
16 [3, 4]
17 >>> number.append(5) #增加
18 >>> number
19 [1, 2, 3, 4, 5]
20 >>> number.insert(1,'6') #将在第二个位置增加一个字符串‘6’
21 >>> number
22 [1, '6', 2, 3, 4, 5]
23 >>> number[0] = 10 #将0位置的元素改为10
24 >>> number
25 [10, '6', 2, 3, 4, 5]
26 >>> number.remove('6') #删除列表中某个指定元素
27 >>> number
28 [10, 2, 3, 4, 5]
29 >>> del number[0] #删除指定位置的元素
30 >>> number
31 [2, 3, 4, 5]
32 >>> number.pop() #删除末尾的元素
33 5
34 >>> number
35 [2, 3, 4]
36 >>> number.index(2) #查找特定元素在列表中的位置
37 0
38 >>> number.count(2) #查找特定元素在列表中的个数
39 1
40 >>> number.reverse() #反转列表
41 >>> number
42 [4, 3, 2]
43 >>> number.sort() #将列表按ASCII码进行排序
44 >>> number
45 [2, 3, 4]
46
47 >>> for i in number: #列表循环
48 print(i)
49
50 2
51 3
52 4
10.元组 一旦创建 不能修改 又被称为只读列表
name = ()
元组相关方法
.count()
.index()
11.字符串操作

1 >>> name = 'chinatang'
2 >>> name.capitalize()
3 'Chinatang'
4 >>> name.count('c')
5 1
6 >>> name.center(50,'$')
7 '$$$$$$$$$$$$$$$$$$$$chinatang$$$$$$$$$$$$$$$$$$$$$'
8 >>> name.encode()
9 b'chinatang'
10 >>> name.decode()
11 Traceback (most recent call last):
12 File "<pyshell#5>", line 1, in <module>
13 name.decode()
14 AttributeError: 'str' object has no attribute 'decode'
15 >>> name.endswith('g')
16 True
17 >>> name.expandtabs
18 <built-in method expandtabs of str object at 0x0284E6D8>
19 >>> name.expandtabs()
20 'chinatang'
21 >>> name.find('c')
22 0
23 >>> name.find('h')
24 1
25 >>> name.format()
26 'chinatang'
27 >>> name.isalnum()
28 True
29 >>> name.isalpha()
30 True
31 >>> name.isdigit()
32 False
33 >>> name.islower()
34 True
35 >>> name.isidentifier()
36 True
37 >>> name.isnumber()
38 Traceback (most recent call last):
39 File "<pyshell#18>", line 1, in <module>
40 name.isnumber()
41 AttributeError: 'str' object has no attribute 'isnumber'
42 >>> name.isnumeric()
43 False
44 >>> name.isspace()
45 False
46 >>> name.istitle()
47 False
48 >>> name.isupper()
49 False
.capitalized()
.count()
.center()
.encode()
.endwith()
.expandtabs()
.find()
.format()
.format-map()
.isalpha()
.isdight()
.isidentifer()
.islower()
.isnumeric()
.isspace()
.istitle()
.isupper()
.join()
.ljust()
.rjust()
.lstrip()
.rstrip()
.strip()
12.字典(key-value)【字典无下标,所以是无序的,通过key寻找对应内容】
into['stu1101'] = 'wu' (增与改的方法)
del into[‘stu1101’] 删除
into.pop() 删除
into.get() 查找
多级字典嵌套与操纵
.values()
.update() 合并字典 交叉更新
.items() 把字典转化成为列表
字典循环 for i in into
12.购物车程序(元组,列表,输入输出,循环,选择半段分支)
13.多级菜单操作题
来源:https://www.cnblogs.com/gjbhpu0308/p/8757043.html
