1.while keyword (infinite loop)
while 条件:
循环体
条件:只要条件是 Ture就可以循环.
==== conditions will be converted to a Boolean value, which contains only Ture or false if it is digital, then, are other than 0 is false Ture. ==
== As long as the string, in addition to what is not to fill "" is false Other We are Ture. ====
Specific procedures
while True:
print("我")
print("是")
print("一")
print("颗")
print("小")
print("小")
print("的")
print("石")
print("头")
- Number is "1", can be executed
while 1:
print("我")
print("是")
print("一")
print("颗")
print("小")
print("小")
print("的")
print("石")
print("头")
- Number is 0, can not be executed
while 0:
print("我")
print("是")
print("一")
print("颗")
print("小")
print("小")
print("的")
print("石")
print("头")
# 程序不执行
- Random string, you can do, even if the space can be executed
s = "A"
while s:
print("我")
print("是")
print("一")
print("颗")
print("小")
print("小")
print("的")
print("石")
print("头")
- If nothing is written, the program does not perform
s = ""
while s:
print("我")
print("是")
print("一")
print("颗")
print("小")
print("小")
print("的")
print("石")
print("头")
# 程序不执行
- while in several common forms
The first: The following code after outputting 1, while loop has been performed, into the loop, behind the print (2), has not performed
print(1)
while 1:
print("我")
print("是")
print("一")
print("颗")
print("小")
print("小")
print("的")
print("石")
print("头")
print(2)
1
我
是
一
颗
小
小
的
石
头
我
是
The second: If you want to output 2 only when the condition is false
falg = "suibian"
while falg:
print(1)
print(2)
当条件为真时,就执行 1111111 一直下去
若是下面的 false 那就输出 2
falg = ""
while falg:
print(1)
print(2)
Exercise
Output correct ordering of 12,345
count = 1
while count <= 5:
print(count)
count = count + 1
The above title, with flashbacks
count = 5
while count >= 1:
print(count)
count = count - 1
2.break , continue
Definition: terminates the current cycle, break the following code will not be executed ( 1 except the conditions as Ture )
while 1:
print(123)
print(456)
break
print(789)
print(111)
#123
456
111
continue: Direct disguised as the last line of code in the loop body continue following code will not be executed (out of the current cycle, continue to the next cycle, such as running, continue suddenly appeared in the runway halfway, then they would have to start from scratch in order to continue to run half and then half this cycle)
while 1:
print(123)
print(456)
continue
print(789)
#
123
456
123
456
123
456
一直循环
break: break the current cycle, the current cycle is terminated.
ready to continue out of the current cycle, the next cycle continues
In common: they do not execute the following code
Format string
When we have problems making business cards, the general process is as follows
\ N newline
a = "--------ofo---------"
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 + "\n" )
But such process is too cumbersome, so with the following string formatting
Formatting advantages: the ability to convert the format consisting of a plurality of sub-strings permutations
s = '''--------ofo-------
name:%s
age:%s
job:%s
-------end------'''
name = input("name")
age = input("age")
job = input("job")
print(s%(name,age,job))
#
namezh
ages
jobx
--------ofo-------
name:zh
age:s
job:x
-------end------
Here some difficult to understand for me
# num = input("学习进度:")
# s11 = "黑哥的学习进度:%s %%"
# print(s11%('234'))
s = f"今天下雨了{input('>>>')}"
print(s)
s11 = "大哥黑的学习进度为:%s"
print(s11%("不错"))
s = f"{1}{2}{3}"
print(s)
# %s 是占的字符串类型的位置
# %d 是占的数字类型的位置
# %% 转换成普通的%号
# 按照位置顺序传递,占位和补位必须要一一对应
while else
while True:
print(E)
else:
print(F)
while True:
print(A)
break
print(B)
Operators
Arithmetic operators
/ (Python2 value acquired is an integer, python3 float is acquired)
// divisible - in addition to the floor
print(5//2)
% Modulus Remainder
** power (power)
Comparison Operators
<
>
== equal
! = Not equal
> = Greater than or equal
<= Less than or equal
Assignment Operators
= Assignment
+ = From Canada
a = 10
a += 1 (相当于 a = a + 1)
print(a)
- = Decrement
* = Squared
Logical Operators
and (with / and) or (or) Not (non)
and: are really taking time to value and back
Are taken and the previous value is false when
Shinichi take a fake fake
print(3 and 4)
print(0 and False)
print(0 and 4)
print(3 and 9 and 5 and 0 and False)
print(5 and False and 9 and 0)
print(1 and 2 and 5 and 9 and 6)
Or: are really taking the time in front of or value
We have taken back or false value when
A true a fake get real
print(1 or 0)
print(1 or 2)
print(0 or False)
print(1 or 9 or 4 or 0 or 9)
#1
级别: () > not > and > or
From left to right execution: (if you are willing to peel layers of my heart ~ ~ ~)
print(9 and 1 or not False and 8 or 0 and 7 and False)
# 1
Member operator
in the presence of
not in the absence of
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
The initial coding
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