老男孩全栈Python九期--day01_初识Python

1.python的环境。

编译型:一次性将所有程序编译成二进制文件。
缺点:开发效率低,不能跨平台。
优点:运行速度快。
:C,C++等等。

解释型:当程序执行时,一行一行的解释。
优点:开发效率高,可以跨平台。
缺点:运行速度慢。
:python ,php,等等。

 

2.python2 python3 区别

python2默认编码方式是ascii码
解决方式:在文件的首行:#-*- encoding:utf-8 -*-
python3 默认编码方式utf-8

 

3.变量。

变量:就是将一些运算的中间结果暂存到内存中,以便后续代码调用。
(1)必须由数字,字母,下划线任意组合,且不能数字开头。
(2)不能是python中的关键字。
['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']
(3)变量具有可描述性。
(4)不能是中文。

 

4.常量。

一直不变的量。 π
BIR_OF_CHINA = 1949

 

5.注释。

方便自己方便他人理解代码。
单行注释:#
多行注释:'''被注释内容''' """被注释内容"""

 

6.用户交互。input
1,等待输入,
2,将你输入的内容赋值给了前面变量。
3,input出来的数据类型全部是str

 

7.基础数据类型初始。
数字:int 12,3,45
+ - * / **
% 取余数
ps:type()
字符串转化成数字:int(str) 条件:str必须是数字组成的。
数字转化成字符串:str(int)
字符串:str,python当中凡是用引号引起来的都是字符串。
可相加:字符串的拼接。
可相乘:str * int
bool:布尔值。 True False。

1 x = 1 + 2 + 3 + 4 + 5
2 print(x)
3 print(x * 5)
4 y = x * 5
5 print(y + 100 - 45 + 2)

 

1 print(100,type(100))
2 print("100",type("type"))
3 print('100',type('100'))
4 # type获取数据类型
5 # 输出结果:
6 # 100 <class 'int'>
7 # 100 <class 'str'>
8 # 100 <class 'str'>

 

 

8.if。

if 条件:
结果

score = int(input("输入分数:"))
if score > 100:
    print("我擦,最高分才100...")
elif score >= 90:
    print("A")
elif score >= 60:
    print("C")
elif score >= 80:
    print("B")
elif score >= 40:
    print("D")
else:
    print("太笨了...E")

 

 

 

9.

while。

while 条件:
循环体
无限循环。
终止循环:(1)改变条件,使其不成立。
     (2)break

1 # break
2 print('11')
3 while True:
4     print('222')
5     print(333)
6     break
7     print(444)
8 print('abc')     

 

continue:

count = 0
while count <= 100 :
    count += 1
    if count > 5 and count < 95:
        continue
    print("loop ", count)

print("-----out of while loop ------")
# 如果continue后面的代码是执行不到的,所以会一直进入无限循环中

 

           

 

posted @ 2018-06-25 12:17  WhoAmISystem  阅读(360)  评论(0编辑  收藏  举报