python全栈-Day 2-0324

 

一、格式化输出format&占位符

name = input('please input your name:')
age = input('plecse input your age:')
height = input('please input your height:')

#两个%%目的是转义,则表示为百分比的意义,若只有一个%,则表示为占位符的意义
print('我的名字是%s,我的年龄是%d,我的身高是%d,学习进度为5%%' %(name,int(age),int(height)))

二、while else

 1、当while循环没有被break打断时,走else;被break打断时,不走else

#当循环被break打断,就不会执行else结果
count = 0
while count <= 5:
    count += 1
    if count == 3:
        break
    print('Loop',count)
else:
    print('循环正常执行完了')
    
#当循环正常执行完毕,未被break打断,就会执行else结果
count = 0
while count <= 5:
    count += 1
    if count == 3:
        pass
    print('Loop',count)
else:
    print('循环正常执行完了')

三、初始编码

1、电脑的传输和存储,实际上都是010101

编码方式

2、ASCII码一共8位,但是7位已经足够使用,因此最左边一位都是0,只适用于美国

8bit (位)== 1byte(字节)

1024byte == 1KB

1024KB == 1MB

1024MB == 1GB

1024GB == 1TB

3、UNICODE(万国码):1个字节表示所有的英文,特殊字符,数组等等;最开始2个字节表示一个中文,后来改成了4个字节

4、UTF-8(UNICODE升级版):1个字节表示所有的英文,特殊字符,数组等等;3个字节表示一个中文;欧洲2个字节

5、GBK:只适用于中国,2个字节表示一个中文,部分中文不包含在内

四、运算符

1、算数运算:+ 、- 、* 、/ 、%(取余)、 **(幂次方)、 //(整除)

2、比较运算:==、!=(等同于<>)、>、<、>=、<=、x is y、x is not y、x in y、x not in y

== 跟 is 的区别, == 比较的是值,is 比较的是对象

3、赋值运算:=、+=、-=、*=、/=、%=、 **=、 //=

4、逻辑运算:and、or、not

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

6、bool的值为True/False(注意大小写),0是True,非0是false,True转换为数字则返回1,False转换为数字则返回0

#计算机是从左到右运算的,and会运算前后结果,or如果前面结果为True则结束运算并输出
print(1 > 2 and 3 < 4)  #False
print(1 > 2 or 3 < 4)  #True
print(not 1)  #False
print(0 or 3)  #3,逻辑运算符前后位数字则返回数字,x or y,x为真则返回x
print(1 and 2)  #2,x and y,x为真则返回y
print(1 > 2 and 3)  #False
print(3 and 1 > 2)  #False
print(2 or  1 < 3)  #2
print(1 <3 or 2)  #True
 

posted @ 2018-07-10 22:55  TXBB哭哭  阅读(126)  评论(0编辑  收藏  举报