Day02
Chapter two
1, While loop:
While loop: death cycle (by circulating condition can be terminated and break)
(1) While --- Keyword
While 条件:
循环体
while True:
print("爱情买卖")
print("痒")
print("年少有为")
print("浮夸")
print("威风堂堂")
print("大悲咒")
print("情锁")
(2) Break terminate the current cycle:
While True:
循环体
Break
语句
while True:
print("爱情买卖")
break
Break ---- must be used in a loop
Break ---- terminate the current through the bad and the code below the break will not be executed
(3) Continue out this cycle, Continue (masquerading as the last line of the loop body) for the next cycle
While True:
循环体
Continue
语句
---- out the Continue this cycle, continue to the next cycle (loop disguised last line of code)
---- must use the Continue cycle and continue below the code will not be executed
while True:
print("爱情买卖")
print("痒")
continue
print("年少有为")
(4) While else --- a whole cycle
While True:
循环体
Else:
语句
While else --- after a while when the condition is not true, execute the statement after else
flag = True
while flag:
print(123)
flag = False
else:
print("循环结束!")
当while循环体中出现了break就不会再执行else
Exercise:
使用while输出10 - 57的数字(包含10和57)
num = 10
while num <= 57:
print(num)
num = num + 1
使用while 输出 100-10 的数字(包含100和10)
num = 100
while num > 9:
print(num)
num = num - 1
2, format
(1)% of placeholder
(2)% s --- stop position of the string (number string can be filled)
(3)% d /% i --- account number position
(4) %% --- Escape
Position and must be accounted for filling one correspondence, when the filler is filled in the order
Variable = Three double quotation marks "" "" "": assigning a string
(5)% s: universal format
(6)% (): In order to fill the position (to correspond with the placeholder)
举例:名片的制作
name = input("name:")
age = input("age:")
addr = input("addr:")
phone = input("phone:")
info = """
-----------info----------
姓名:%s
年龄:%d
公司:%s
电话:%d
------------end-----------
"""%(name,int(age),addr,int(phone))
print(info)
f”{ }”
Python3.6 version and above to use the f "{}": f "{ 'marry' learning progress 2%}"
Print(f”{input(‘>>>’)}{15}{‘男’}{ }”)
name = "小明"
print(f"{name}的学习进度2%")
print(f"{input('>>>')},{23},{34},{45}")
print(f"{input('>>>')},{23},{34},{45}")
print(f"{'meet'},{15},{'女'}")
3, commonly used operators:
(1) arithmetic operators:
+ - * /% (Remainder (modulus)) * (Power (power)) // (divisible (rounded down) (except floor))
(2) comparison operators:
> <<=> = == (equal to)! = (Not equal)
(3) assignment operator:
+ = - = = * / =% = (modulo etc.) ** = (power, etc.) // = (rounding etc.)
(4) logical operators:
and (with): and operations, are true is true, there is a fake is a fake.
and computing, it is really time to choose the content and behind
and the operations are select content and false front when
or (or): or operation, is really only one true
or operations, are true when selecting content or front
or operations, have chosen the content or behind false time
not (non): No
(Priority of logical operators: ()> not> and> or)
(5) members of the operator:
in: In
not in: not
4, encoding acquaintance:
(1) ASCII code: 256 English one byte, does not support Chinese
(2) GBK (GB): English one-byte Chinese two bytes
(3) unicode (Unicode): English 4 bytes 4 bytes Chinese
(4) Utf-8: The most popular code set (codebook) English one byte; 2 bytes in Europe; 3 bytes Asia
Win - encoding gbk linux - encoding utf-8 mac - encoding utf-8
5, unit conversion:
== 1 byte 8 (1Bytes == 8bit)
1B == 8b
1KB == 1024 B
1MB == 1024 KB
1GB ==1024 MB
1TB ==1024 GB
1PB ==1024 TB
1EB ==1024 PB