Learning the next day: Content

1.while cycle

while - Keyword (infinite loop)

if 条件:
    结果
    
while 条件:
    循环体
while True: #真 执行
    print("A")
    print("B")
    print("C")
    print("D")
    print("E")
    print("F")
    print("G")

while False: # 假 不执行
    print("A")
    print("B")
    print("C")
    print("D")
    print("E")
    print("F")
    print("G")

print(1)
while False: # 假 执行不到
    print("A")
    print("B")
    print("C")
    print("D")
    print("E")
    print("F")
    print("G")
print(2)
B = True
while B:
    print(1)
print(2)

print(bool(0))
数字中非零的的都是True

B = 1
while B <= 9:
    print(B)
    B = B+1
倒序
B = 6
while B >= -5:
    print(B)
    B = B-1

顺序
B = -6
while B <= 5:
    print(B)
    B = B+1


正序25-57
B = 25
while B <= 57:
    print(B)
    B = B+1

倒叙57-25
B = 57
while B >= 25:
    print(B)
    B = B-1

break continue

while True:
    print(A)
    print(B)
    break #终止当前循环 birak下方的代码不执行
    print(C)
print(D)

while True:
    print(A)
    print(B)
    continue #伪装成临时当作循环体中的最后一行代码(跳出当前循环继续下一个循环)
             #下面代码不会执行
    print(C)
print(D)

while else

while True:
    print(E)
else:
    print(F)

while True:
    print(A)
    break
print(B)

to sum up

    打断循环的方式:
        1.自己修改条件
        2.break
    break ——打破当前循环(终止当前循环)
    continue ——跳出当前循环继续下次循环(伪装成临时当作循环体中的最后一行代码)
    break和continue相同之处:他们一下的代码都不执行

Exercise

Code: 25--57--25
def func(x):
    print(x)
    if x < 57:
        x += 1
        func(x)
        print(x - 1)
func(25)
Code: cycling
msg = int(input("输入序号选择格式(0/1):"))
if msg == 0:
    print("用户退出成功!")
if msg == 1:
    flag = True
    while flag:
        user = input("请输入用户名:")
        pwd = input("请输入密码:")
        if user == "大黑哥" and pwd == "123456":
            print("输入正确")
            flag = False
        else:
            print("请重新输入!")

2. String Format

content

A = input("请输入你的年龄:")
B = "你已活的时长为:%s%%"
print(B%(A))
a = "------------- info -------------"
b = "name:"
c = "age:"
d = "job:"
e = "-------------- end -------------"
name = input("name")
age = input("age")
job = input("job")
print(a + "\n" + b + name + "\n" + c + age + "\n"+ d + job + "\n" +e)


s = """ ------------- info -------------
name:%s
age:%s
job:%s
-------------- end -------------
"""
name = input("name")
age = int(input("age"))
job = input("job")
print(s%(name,age,job))
num = input('学习进度:')
s11 = "大哥黑的学习进度为:%s %%"
print(s11%(num))

s = f"今天下雨了{input('>>>')}"
print(s)

s11 = "大哥黑的学习进度为:%s"
print(s11%("不错"))

s = f"{1}{2}{3}"
print(s)

to sum up

%s 是占的字符串类型的位置
%d 是占的数字类型的位置
%% 转换成普通的%号
按照位置顺序传递,占位和补位必须要一一对应

3. Operator

Order of operations

() > not > and > or
从左向右执行

Arithmetic operators

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

Comparison Operators

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

Assignment Operators

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

Logical Operators

and (与/和)
or (或)
not (非)

print(3 and 4)
print(0 and 4)
print(0 and False)

and 都为真的时候取and后边的值
and 都为假的时候取and前面的值
and 一真一假取假的

print(3 and 5 and 9 and 0 and False)
print(5 and False and 9 and 0)
print(1 and 2 and 5 and 9 and 6)

print(1 or 0)
print(1 or 2)
print(0 or False)

or 都为真的时候取or前边的值
or 都为假的时候取or后面的值
or 一真一假取真的

print(1 or 9 or 4 or 0 or 9)
print(not False)

print(9 and 1 or not False and 8 or 0 and 7 and False)

Member operator

in  存在
not in 不存在

s = "alexdsb"
if "sb" not in s:
    print(True)
else:
    print(False)

to sum up

    运算顺序:() > not > and > or 从左向右执行
    算数运算符 : + - * / // ** %
    比较运算符: > < >= <= == !=
    赋值运算符: = += -= *= /= //= **= %=
    逻辑运算符: and or not () > not > and > or
    成员运算符: in not in

4. encoded initial

understanding

今 0101
天 0110
晚 0010
上 0001
去 1001
便 1000
利 0100
店 1111

00000101  00000110  0010000110011001

linux -- utf-8
mac -- utf-8
windows -- gbk

Four kinds of (important)

ascii (老美)不支持中文
gbk    (国标) 英文 8位  中文16位
unicode (万国码)英文16 位 中文 32位
utf-8   (可变长的编码) 英文8位 欧洲文 16位 亚洲24位

Unit Conversion

1字节 = 8位
1Bytes = 8bit ***
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB
1024TB = 1PB
1024PB = 1EB
1024EB = 1ZB
1024ZB = 1YB
1024YB = 1NB
1024NB = 1DB

Guess you like

Origin www.cnblogs.com/changxin7/p/11139425.html