day02
1.while cycle - while keyword
while the space colon condition
Indent loop
while 5>4:
print("Hello World!")
Digital Africa 0 is True
# 正序25~57![](https://img2018.cnblogs.com/blog/1617228/201907/1617228-20190705192654502-2028519452.png)
# count = 25
# while count <= 57:
# print(count)
# count += 1
# 倒叙57~25
# count = 57
# while count >= 25:
# print(count)
# count -= 1
break terminates the current cycle, break following a code execution loop
Skip continue this cycle, the next cycle continues (the following code is not performed) #continue disguised last line of the loop
break and continue in common:
The following code is not executed loop
Controlled conditions while loop
Break the cycle way:
1. Modify the conditions themselves
2.break
topic:
# num = int(input("请输入数字:"))
# while num == 1:
# user = input("请输入用户名:")
# pwd = input("请输入密码:")
# if user == "zcy" and pwd == "123":
# print("登陆成功!")
# break
# else:
# print("用户名或密码错误!")
# else:
# print("退出成功!")
while else: while the condition is not established when executed, condition is not satisfied when he executed else
2. Output Formatting
% S (string type)% d (digital type)
Transmitted in order of position, and occupying one-fill bits must be
If the string is to be output in%, with escape %%
name = input("姓名:")
age = input("年龄:")
msg = '姓名:%s,年龄:%d'%(name,int(age))
print(msg)
% - placeholder
% S - string of bits representing
% D - accounted digit
%% - escaped into ordinary%
.format
name = input("姓名:")
age = input("年龄:")
msg = '姓名:{},年龄:{}'.format(name,int(age))
print(msg)
name = input("姓名:")
age = input("年龄:")
msg = '姓名:{1},年龄:{0}'.format(int(age),name)
print(msg)
f '1 {} string, the string 2 {}' (python 3.6 above)
name = input("姓名:")
age = input("年龄:")
msg = f'姓名{name},年龄{age}'
print(msg)
3. Operator
Arithmetic Operators
+ Plus
- Less
* Multiplication
/ Python2 acquisition is an integer python3 obtained is a float
// (divisible - except the floor)
** power (power)
% Modulus (remainder)
Comparison Operators
> Greater than
<Less than
== equal
! = Not equal
> = Greater than or equal
<= Less than or equal
Assignment Operators
= Assignment
+ = From Canada
- = Decrement
* = Squared
/ = From the addition
// = from the floor in addition to
** = from power
Since more than% =
Logical Operators
and and
or 或
not non
and are really behind and take the time value
print( 3 and 4) #4
and the front and are taken when the value is false (the front is false, and no later determination)
print( 0 and False) #0
a true and a false false taken (front face is false, and no later determination)
print( 0 and 4) #0
print( 4 and 0) #0
or are taken or true value when the front (front is true or not is determined later)
print( 3 or 4) #3
or have taken back or false value when
print( 0 or False) #False
taking a true or a false true (true is in front of, behind or not determined)
print( 0 or 4) #4
print( 4 or 0) #4
priority:
()> not > and > or
Member operator
in the presence of
not in the absence of
4. The initial coding (coding set)
Ascii (United States) does not support Chinese
GBK (GB, also known as GBK2312) English 8 (1Bytes) Chinese 16 (2Bytes)
Unicode (Unicode) English 16 (2Bytes) Chinese 32 (4Bytes)
UTF-8 (variable length coding) English 8 (1Bytes) European paper 16 (2Bytes) Asia (24) (3Bytes)
Linux -- UTF-8
Mac -- UTF-8
Windows --GBK
Unit conversion:
- 1Bytes = 8bit
- 1KB = 1024Bytes
- 1MB = 1024KB
- 1GB = 1024MB
- 1TB = 1024GB
- 1PB = 1024TB
Other knowledge
python print(a,b,c,d,sep = "\n") #sep = "\n" 换行