A .while loop
1. Basic loop (infinite loop)
while 条件:
循环体
2. Using while counting
count = 0 # 数字里面非零的都为True
while True:
count = count + 1
print(count)
3. The number of times while the control loop
count = 0
while count < 100:
count = count + 1
print(count)
# 打断循环的方式
1.自己修改条件
2.使用break关键字
4.break keyword
break-- terminate the current cycle, the code below will not be executed.
num = 1
while num < 6:
print(num)
num = num + 1
break
print("end")
5.continue keyword
continue-- temporarily as a last line of code in the loop body (jump out when the cycle continues next cycle), the following code will not be executed.
num = 1
while num < 6:
print(num)
num = num + 1
countinue
print("end")
# break和continue的相同之处:他们以下的代码都不会被执行
6.while else
# 循环一
while True:
if 3 > 2:
print("你好")
break
else:
print("不好")
# 循环二
while True:
if 3 > 2:
print("你好")
print("不好")
II. Formatted output
Formatting a string passed by ordinal position, and occupying fill bits must be one correspondence.
%---占位
%s---是占的字符串类型的位置
%d(%i)---是占的数字类型的位置
%%---转换成普通的%
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)
# %d 数字类型
num = input('学习进度:')
s11 = "大哥黑的学习进度为:%s %%"
print(s11%(num)
# %s 字符串类型
s = """ ------------- info -------------
name:%s
age:%s
job:%s
-------------- end -------------
"""
name = input("name")
age = int(input("age"))
job = input("job")
print(s%(name,age,job))
# 其他方式
s = f"今天下雨了{input('>>>')}"
print(s)
s = f"{1}{2}{3}"
print(s)
III. Operator
1. The arithmetic operators
Suppose a = 10, b = 20
Operators | description | Examples |
---|---|---|
+ | plus | a+b #30 |
- | Less | a-b #-10 |
* | Multiply | a*b # 200 |
/ | except | b/a #2 |
% | Modulo (the number of remainder) | b%a #0 |
** | power | a**b #10000000000000000 |
// | Divisible (except flooring) | 20//10 #2.0 |
2. Comparison Operators
Operators | description |
---|---|
== | equal |
!= | not equal to |
> | more than the |
< | Less than |
>= | greater or equal to |
<= | Less than or equal |
3. assignment operator
Operators | description |
---|---|
= | Simple assignment operator |
+= | Addition assignment operator |
-= | Subtraction assignment operator |
*= | Multiplication assignment operator |
/= | Division assignment operator |
%= | Modulo assignment operator |
**= | Power assignment operator |
//= | Assignment operator take divisible |
4. Logical Operators
Operators | description |
---|---|
and | And / and |
or | or |
not | non- |
逻辑运算的顺序排列:从左往右开始执行
() > not > and > or
and or 一真一假
都为真: 取后面的 取前面的 取假的
都为假: 取前面的 去后面的 取真的
not True: False
not False: True
The member operator
in -- 存在
not in -- 不存在
IV. Acquaintance coding (coding set)
1.ASCII (United States)
Does not support Chinese
2.GBK (GB)
English --8 bit 1 byte
Chinese --16 bytes 2 bits
3.Unicode (Unicode)
Byte 2 Bit English --16
Chinese --32 bit byte 4
4.Utf-8
English --8 bit 1 byte
--16-bit 2-byte European languages
Asia --24-bit byte 3
5. Unit Conversion
#1字节=8位(1byte=8bit)
8bit = 1byte
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB
1024TB = 1PB
1024TB = 1EB
1024EB = 1ZB
1024ZB = 1YB
1024YB = 1NB
1024NB = 1DB