基础知识2

while循环

1,whlie 条件:             (控制while循环的三个东西:break,continue,条件)

  循环体

  print()

实例1:循环播放音乐

whlie True:
    print("歌名")

实例2:使用whlie循环输出1-100

num = 0
while num < 101:
    print(num)
    num = num + 1

1.1 break(终止循环,以下代码均不执行)

实例:

num = 0
while num<10:
    print(num)
    num += 1
    break
print("end")

1.2continue(结束本次循环,继续下次循环)

实例:输出1234678910

num = 1
while num<11:
    if num == 5:
        num = num + 1
        continue (临时见底,到此以下不循环)
    print(num)
    num = num + 1

字符串格式化输出

format; %s,%d; f'姓名:{name},年龄:{age}'

name = input("姓名:")
age = input("年龄:")
msg = '姓名:%s,年龄:%d'%(name,int(age))
print(msg)

# 一个%是占位,补位通过在后面添加'%()'来补充

%%在格式化输出中叫做%, %%转义,数量一一对应.

数据类型转换

运算方式

赋值运算

+= -= *= /= //=(整除) **=(次方) %=(求余)

比较运算

< > >= <= == !=

成员运算

in not in

逻辑运算

and or not

and or 比较结果

都为真时,or选前面,and选后面

都为假时,or选后面,and选前面

一真一假,or选真,and选甲

初识编码

ASCII 美国 , 没有中文 , 256(一个字节8位)

GBK 中国 , 2字节 , 16位

Unicode 万国码 , 初始2字节16位 ; 后期4字节32位

utf-8 可变编码 ,

英文1字节8位

欧洲2字节16位

亚洲3字节24位

单位转化 : bit 位 ; bytes字节

1B == 8bit

1024B == 1KB

1024KB == 1MB

1024MB == 1GB

1024GB == 1TB

猜你喜欢

转载自www.cnblogs.com/py8318/p/10196316.html