1. Formatted output
The formatted output is used to represent the content information that outputs the computer and user interaction with a framework, in the following format:
The basic information framework is represented by a string, where the contents of the user interaction are represented by%s,%d, respectively, by means of strings and numbers. (special hint, user interaction content is all str format, note conversion)
The following uses% (XXX,XXX,XXX) to correspond to each of the previous placeholders, respectively. (Note that it is one by one correspondence, the corresponding error (location format) will be incorrect)
1Name = input ('Please enter your name:')2Age = Input ('Please enter your age:')3Job = input ('Please enter your work:')4Hobbie = input ('Your Hobbies:')5 6msg =" "------------Info of%s-----------7 Name:%s8 Age :%d9 Job:%sTen Hobbie:%s One -------------End-----------------" " A%(Name,name,int (age), Job,hobbie) - Print(msg)
You should also pay attention to one problem:
If you also want to represent a keyword in a string, the same as a placeholder (%s%d) requires a double write percent. The first% unlocks the function of the keyword, showing the result is the content after the first%.
1 name = input (' Please enter name ')2 age = input (' Please enter ages ' )3 height = input (' Please enter height ')4" My name is%s and this year%s height%s Learning progress is 3%%s" %(name,age,height)5Print( Msg
2.while...else ...
The else function behind the while loop is that the statement after the else is executed when the while cycle is executed properly and the middle is not interrupted by a break.
(The direct word is that the condition of the else is not executed after the break is terminated)
1Count =02 whileCount <= 5 :3Count + = 14 ifCount = = 3: Break5 Print("Loop", Count)6 7 Else:8 Print("The loop is running, it's done.")9 Print("-----out of a while loop------")
3. Content encoding
Simple content coding can be understood as a set of password system to convert computer language and human language.
1 time the earliest encoding is the ASCII code, a set of computer coding systems based on the Latin alphabet, mainly used to display modern English and other Western European languages, which can be represented at most 8 bits (one byte), i.e.: 2**8 =
256, so the ASCII code can only represent 256 symbols at a maximum. (later Unicode is born because there is too little content to represent)
ASCII left one more, is the first, all 0, at the time it seems to be extended later.
2 Unicode (Universal code) is a character encoding that is used on a computer. Unicode is created to address the limitations of traditional character encoding schemes, and it sets a uniform and unique for each character in each language.
Binary encoding, which specifies that although some characters and symbols are represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536, (note: This is said to be at least 2 bytes, possibly more) (because still cannot represent enough
The content of the UTF-8 was later born)
3 UTF-8 is the compression and optimization of Unicode encoding, he no longer uses a minimum of 2 bytes, but instead all the characters and symbols are categorized: the content in the ASCII code is saved with 1 bytes, the characters in Europe are saved in 2 bytes, the characters in East Asia are saved in 3 bytes ...
The ASCII code cannot be expressed in Chinese, so add a word to the front
1 # !/usr/bin/env python 2 # -*-coding:utf-8-*-(this sentence)
The conversion relationship between units is as follows:
4. Basic operators
Computer can be carried out many kinds of operations, can not only subtraction so simple, the operation by category can be divided into arithmetic operations, comparison operations, logical operations, assignment operations, member operations, identity operations, bit operations, in this only to introduce arithmetic operations, comparison operations, logical operations, assignment operations.
Arithmetic operations
Comparison operation
Assignment operations
Logical operations
1 Logical Operation Priority: () >not>and>or the same priority is computed from left to right. (see example)
13>4or4<3 and1==1F21 < 2 and3 < 4or1>2T32 > 1 and3 < 4or4 > 5 and2 < 1T41 > 2 and3 < 4or4 > 5 and2 > 1or9 < 8F51 > 1 and3 < 4or4 > 5 and2 > 1 and9 > 8or7 < 6F6 not2 > 1 and3 < 4or4 > 5 and2 > 1 and9 > 8or7 < 6 F
2 x or Y, (just remember that the rules for or and and or are just the opposite) (1 is true 0 is false)
X is true, the value is X,x is False, the value is y;
X and Y, X is true, the value is y,x false, and the value is x.
!!! The number is converted to a Boolean value, and non-zero is converted to a Boolean value after the true,0 is false.
!!! True converts to numbers is 1,false converted into numbers is 0.!!!
Python Day-2