python full stack development day02

1. Format the output
Use string concatenation to form a template:
This leads to the formatted output: (production of personal business cards)
Use of formatted output: % placeholder s represents a character, d represents a number
%s
%d
%r???
The first format: (must be one-to-one correspondence)
The second format: (no one-to-one correspondence is required)
Note: Formatted output, in formatted output, simply expressing % needs to be expressed as %%
2.while...else...(will be used in specific scenarios)
When the while loop is not interrupted by break, go else
count = 0
while count <=5:
count += 1
print('loop',count)
else:
print('This loop is over!')
When the while loop is interrupted by break, do not go else
count = 0
while True:
count += 1
print('loop',count)
if count == 5:
break
else:
print('This loop is over!')
3. Operators
Logical Operators (New Knowledge Point)
and with
or 或
not not
The first case: the logical operator is preceded by a comparison operation (look at the priority first)
Priority concept: () > not > and > or , the same priority is calculated from left to right
4 True 5 Flase 6 Flase
The second case: the logical operators are all numbers before and after (the same priority is calculated from left to right)
x or y if x True , return x , else y
x and y if x True , return y , else x
(and is the opposite of or)
Other people's ideas:
and= and and 0 get 0 return the right
or = or or 1 is 1 returns the left
( and > or )
Conversion of numbers and booleans (new knowledge point)
int--------->bool non-zero True zero False
bool---------->int True 1,Flase 0
 
print(1>2 and 3 or 4)---------------->4
When operating logical operators, look at and or not first, and operate from left to right according to the priority level.
The thinking process of summarizing the rules is as follows:
print(1 > 2 and 3 or 4) #4
print(3 and 1 > 2 or 4) #4
print(4 and 3 or 1 > 2) #3
4. Coding first knowledge
Spy Movie: Didi Hi-Lo 01010101
Computer file storage, and file transfer 0101010
The primary codebook in the computer: ASCII (only includes English, numbers and special symbols)
ASCII code is: a comparison table of binary and characters
The reason why the leftmost is 0 is to reserve one bit for later use
Eight bits are equal to one byte 8bit=1Byte
One byte represents one character (character: the smallest unit of content, for example: China ----->'中' is a character, '国' is a character
A------->65
a------->97
Universal Code: The initial creation of Unicode is 16-bit two bytes representing a character
After the upgrade, 32 bits, four bytes represent one character. The disadvantage is that it causes a waste of resources.
Upgrade again for Unicode ------------->UTF-8, UTF-16 (represent at least one character with 16 bits)
UTF-8: use at least eight digits to represent a character
Letters are represented by one byte (8 bits), European characters are represented by two bytes (16 bits), and Asian characters are represented by three bytes (24 bits)
GBK: National Standard
Letters are represented by one byte (8 bits), and Chinese are represented by two bytes (16 bits)
Unit conversion:
1Byte=8bit
1KB=1024B
1MB=1024KB
1GB=1024MB
1TB=1024GB
 
Day3 default code:
The conversion relationship between Bit, Bytes, Kb, Mb, Gb, Tb.
Unicode, utf-8, gbk, each encoding English, Chinese, are represented by several bytes respectively.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325117233&siteId=291194637