python复习day1

Part1开发:

开发语言:
1)高级语言:Python Java、PHP C# Go ruby C++… ===》 字节码
2)低级语言:C、汇编 ===》 机器码

语言之间的对比:
1)PHP类:适用于写网页,局限性
2)Python Java: 及可以写网页 也可以写后台功能
– Python执行效率低,开发效率高
– Java执行效率高, 开发效率低

Python种类:
2)JPython
3)IronPython
4)JavaScriptPython
5)RubyPython
6)CPython **********

pypy 这是用CPython开发的Python

安装:
Python安装在OS上,
执行操作:
写一个文件文件中按照python的规则写,将文件交给Python软件,读取文件中的内容,然后进行转换和执行,最终获取结果。

Python软件 ==> Python解释器(内存管理)

下载:
Python3 在继续更新
Python2 在继续更新

Window:
python2
python3
# 环境变量
配环境变量:C:\Program Files\Microsoft Games\Solitaire
>>>Solitaire

C:\Program Files\Microsoft Games\Solitaire\Solitaire

Linux(centos7) :
python2.7
python3.6

 

part2

a. Python基础
– 基础
1. 第一句python
– 后缀名是可以是任意?
– 导入模块时,如果不是.py文件
==> 以后文件后缀名是 .py

2. 两种执行方式
python解释器 py文件路径
python 进入解释器:
实时输入并获取到执行结果

3. 解释器路径
#!/usr/bin/env python
4. 编码
# -*- coding:utf8 -*-

ascill 00000000

& 00000001

unicode 0000000000000000+

& 0000000000000001
中 001000000000000111110010

utf-8 能用多少表示就是用多少表示
& 00000001
中 001000000000000111110010

Python3 无需关注
Python2 每个文件中只要出现中文,头部必须加

5. 执行一个操作
提醒用户输入:用户和密码
获取用户名和密码,检测:用户名=root 密码=root
正确:登录成功
错误:登陆失败

a. input的用法,永远等待,直到用户输入了值,就会将输入的值赋值给一个东西

6. 变量名

– 字母
– 数字
– 下划线
PS:
数字不能开头
不能是关键字
最好不好和python内置的东西重复 

[root@localhost tmp]# python2.7
Python 2.7.5 (default, Nov 16 2020, 22:23:17)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyword
>>> keyword.kwlist
['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']

 

name = “石正文”

7. 条件语句
缩进用4个空格
a.
n1 = input(‘>>>’)

if “alex” == “alex”:
n2 = input(‘>>>’)
if n2 == “确认”:
print(‘alex SB’)
else:
print(‘alex DB’)
else:
print(‘error’)

注意:
n1 = “alex” 赋值
n1 == ‘alex’ 比较,
b.

if 条件1:
pass
elif 条件2:
pass
elif 条件3:
pass
else:
pass

print(‘end’)

c. 条件1
and or

if n1 == “alex” or n2 == “alex!23”:
print(‘OK’)
else:
print(‘OK’)

PS:
pass 代指空代码,无意义,仅仅用于表示代码块

8. 基本数据类型

字符串 – n1 = “alex” n2 = ‘root’ n3 = “””eric””” n4=”’tony”’
数字 – age=21 weight = 64 fight = 5

加减乘除等:
字符串:
加法:
n1 = “alex”
n2 = “sb”
n4 = “db”
n3 = n1 + n2 + n4
# “alexsbdb”

乘法:
n1 = “alex”
n3 = n1 * 10
数字:
n1 = 9
n2 = 2

n3 = n1 + n2
n3 = n1 – n2
n3 = n1 * n2
n3 = n1 / n2
n3 = n1 % n2
n3 = n1 ** n2

出题:
11 12 13 …

num = 12
n = num % 2
if n == 0:
print(‘偶数’)
else:
print(‘奇数’)

9. 循环
死循环

while 1==1:
print(‘ok’)

10. 练习题(if条件语句;while循环;奇数偶数)

1)提示用户输入:用户和密码,获取用户名和密码,检测:用户名=admin 密码=123456,满足下列的条件
a)正确:登录成功
b)错误:登陆失败
c)用户名或者密码错了3次就退出

[root@teddylu1987 tmp]# grep -n "/*" login.py 
1:# -*- coding:utf8 -*-
2:
3:count = 0
4:while count < 3:
5:
6:      username = raw_input("请输入用户名: ")
7:      password = raw_input("请输入密码: ")
8:
9:#print n1
10:#print n2
11:#if n1 == "admin" and n2 == "123456":
12:#            print("登录成功!!!")
13:#else:
14:#            print("登录失败!!!")
15:     if username == 'admin' and password == '123456':
16:             print ('welcome to login!!!')
17:             break
18:     else:
19:             print('usename or password is worng!!!')
20:     count = count + 1
21:

2)使用while循环输入 1 2 3 4 5 6 8 9 10

[root@teddylu1987 day1]# grep -n "/*" 1.py 
1:# -*- coding:utf8 -*-
2:
3:n = 1
4:while n < 11:
5:      if n == 7:
6:              pass
7:      else:
8:              print(n)
9:      n = n + 1

3)求1-100的所有数的和

[root@teddylu1987 day1]# grep -n "/*" 2.py  
1:# -*- coding:utf8 -*-
2:
3:n = 1
4:s = 0
5:while n < 101:
6:      s = s + n
7:      n = n + 1
8:print(s)
[root@teddylu1987 day1]# python2.7 2.py 
5050

4)输出 1-100 内的所有奇数

[root@teddylu1987 day1]# grep -n "/*" 4.py  
1:# -*- coding:utf8 -*-
2:
3:n = 1
4:while n < 101:
5:      tmp = n % 2
6:      if tmp == 0:
7:              pass
8:      else:
9:              print(n)
10:     n = n + 1
[root@teddylu1987 day1]# python2.7 4.py    
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99

5)输出 1-100 内的所有偶数

[root@teddylu1987 day1]# grep -n "/*" 3.py  
1:# -*- coding:utf8 -*-
2:
3:n = 1
4:while n < 101:
5:      tmp= n % 2
6:      if tmp == 0:
7:              print(n)
8:      else:
9:              pass
10:     n = n + 1
[root@teddylu1987 day1]# python2.7 3.py    
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100

6)求1-2+3-4+5 … 99的所有数的和

[root@teddylu1987 day1]# grep -n "/*" 99.py 
1:# -*- coding:utf8 -*-
2:
3:n = 1
4:s = 0
5:while n < 100:
6:      tmp = n % 2
7:      if tmp == 0 :
8:              s = s - n
9:      else:
10:             s = s + n
11:     n = n + 1
12:print(s)
[root@teddylu1987 day1]# python2.7 99.py 
50

基本数据类型
– 函数
– 面向对象

b. 网络编程

c. WEB框架
– 用于写网站

d. 设计模式 + 算法

e. 项目阶段

python复习day1
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x