day1_回顾

1、昨日内容回顾
编译型:一次性将全部的代码编译成二进制文件。
c,c++
优点:运行效率高
缺点:开发速度慢,不能跨平台
解释型:当程序运行时,从上至下一行一行的解释成二进制。
优点:开发速度快,效率高,可以跨平台。
缺点:运行效率低。
python2x和python3x宏观上的区别:
python2x源码,重复率高,不规范,而且Python崇尚的是简单优美、清晰,所以龟叔创建了python3,规范化。

在python2首行:# -*- encoding:utf-8 -*-解决python2中文报错问题
变量:由数字、字母、下划线任意组合,且不能以数字开头
具有可描述性
不能用Python中的关键字
不能用中文,不能用拼音
常量:约定俗成 不可更改,全部是大写字母。
注释:
单行注释:#
多行注释:''' ''' """ """
用户交互input:
数据类型全部是str
基础数据类型:bool True False
int +-*/% // **
str:加引号的就是str
+可以与数字*
if 条件:
结果

if 条件:
结果
else:
结果

if 条件:
结果
elif 条件:
结果
elif 条件:
结果
......
else:
结果

if 条件:
if条件:结果
if....
else:结果

while 条件:
结果
1,改变条件。
2,break

continue:结束本次循环,继续下一次循环。

 

2、作业讲解


3、pycharm下载安装

4、格式化输出。

name = input("请输入姓名:")
age = input("请输入年龄:")
job = input("请输入工作:")
hobbie = input("你的爱好:")

msg = '''------------ info of %s -----------
Name  : %s
Age   : %d
job   : %s
Hobbie: %s
------------- end -----------------''' %(name,name,int(age),job,hobbie)
print(msg)

在格式化输出内容中含有%,应在添加一个%,就可正常输出内容

name = input("请输入姓名")
age = input("请输入年龄")
height = input("请输入身高")
msg = '我叫%s,今年%s 身高 %s 学习进度为3%%' %(name,age,height)
print(msg)

5、while ... else...

while 后面的else 作用是指,当while 循环正常执行完,中间没有被break 中止的话,就会执行else后面的语句

count = 0
while count <= 5 :
    count += 1
    if count == 3:break
    print("Loop",count)

else:
    print("循环正常执行完啦")
print("-----out of while loop ------")

6、初始编码
电脑的传输,还有储存的实际上都是01010101010
美国:ascii码 为了解决这个全球化的文字问题,创建了一个万国码,unicode
最开始
1个字节 表示所有的英文,特殊字符,数字等等
2个字节,16位表示一个中文,不够,unicode一个中文用四个字节表示,32位
你 00000000 00000000 00000000 00000000
中文 9万多字,
升级版 utf-8 一个中文 3个字节去表示

gbk国内使用,一个中文用个字节

7、运算符
逻辑运算符

针对逻辑运算的进一步研究:

  1,在没有()的情况下not 优先级高于 and,and优先级高于or,即优先级关系为( )>not>and>or,同一优先级从左往右计算。

优先级:() > not > and > or

例题

判断下列逻辑语句的True,False。

1,3>4 or 4<3 and 1==1  #False
2,1 < 2 and 3 < 4 or 1>2  #True
3,2 > 1 and 3 < 4 or 4 > 5 and 2 < 1  #True
4,1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8  #False
5,1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 66  #False
6,not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6  #False

     2,x or y x为真(非零),则返回x;x为假(0),返回y

print(1 or 2) #1
print(3 or 2) #3
print(0 or 2) #2
print(0 or 100) #100

  x and y x为真(非零),则返回y;x为假(0),返回x

print(1 and 2) #2
print(3 and 2) #2
print(0 and 2) #0
print(0 and 100) #0

  int---->bool 非零转换成bool True 0转换成bool,是False

print(bool(2)) #True
print(bool(-2)) #True
print(bool(0)) #False

  bool---->int

print(int(True)) #1
print(int(False)) #0

 例题

print(2 or 100 or 3 or 4) #2
print(0 or 4 and 3 or 2 ) #3

  

 

 

  

posted @ 2019-01-14 17:52  taoziya  阅读(112)  评论(0)    收藏  举报