python入门02

python入门02(two)

内容大纲

1.while循环

2.字符串格式化

3.运算符

4.编码初识

1.while循环

1.while 关键字 死循环

while 条件:
    循环体
print(bool(0))
数字中非零的都是True
count = 1
while count <= 5;
    print(count)
    count = count + 1
 正序打印从 25 - 57
 count = 25
 while count <= 57:
     print(count)
     count = count + 1

 倒序打印从 57 - 25
 count = 57
 while count >= 25:
     print(count)
     count = count - 1
while True:
    print(123)
    print(234)
    break   # 终止当前循环,break下方的代码不会进行执行
    print(345)
print(1111)
while True:
    print(123)
    print(234)
    continue
    #continue 伪装成循环体中的最后一行代码(跳出当前循环继续下次循环)
    #continue 下面的代码不会执行
    print(345)
print(1111)

总结:

打断循环的方式:

1.自己修改条件

2.break

break -- 打破当前循环 (终止当前循环)

continue -- 跳出当前循环继续下次循环(将continue伪装成循环体中的最后一个行代码)

break和continue相同之处:他们以下的代码都不执行

2.字符串格式化

s11 = "王二狗的工作进度为:%s"
print(s11%("不错"))

s = f"{1}{2}{3}"
print(s)
%s 是占的字符串类型的位置
%d 是占的数字类型的位置
%% 转换成普通的%号
按照位置顺序传递,占位和补位必须要一一对应
字符串格式化的三种表示方法:
print("我叫%s,今年%s岁了"%("小李",20))
print("我叫{},今年{}岁了".format("小李",20))
print(f'我叫{"小李"},今年{20}岁了')

3.运算符

算数运算符

+
-
*
/ python2获取的值是整数,python3获取的是浮点数(小数2.5)
print(5/2)
//(整除-- 地板除)
print(5 // 2)
** 幂(次方)
print(3**2)
% 模 (取余)
print(5 % 2)

比较运算符

>
<
== (等于)
!= (不等于)
>=
<=

赋值运算符

= 赋值
+= 自加
a = 10
a += 1 # a = a + 1
print(a)
-= 自减
*= 自乘
a = 10
a *= 2  # a = a * 2
print(a)
/=
//=
**=
%=

逻辑运算符

and (与/和)
or (或)
not (非)
and 都为真的时候取and后边的值
and 都为假的时候取and前面的值
and 一真一假取假的
or 都为真的时候取or前边的值
or 都为假的时候取or后面的值
or 一真一假取真的
() > not > and > or
从左向右执行
成员运算符
in  存在
not in 不存在

4.编码初识

ascii (美国)不支持中文
gbk    (国标) 英文 8位  中文16位
unicode (万国码)英文16 位 中文 32位
utf-8   (可变长的编码) 英文8位 欧洲文 16位 亚洲24位
linux系统 -- utf-8
mac系统 -- utf-8
windows系统 -- gbk
单位转换:
1字节 = 8位
1Bytes = 8bit ***
1024Bytes = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB  *** 
1024TB = 1PB
1024PB = 1EB

猜你喜欢

转载自www.cnblogs.com/liubing8/p/11141504.html