operators and encodings
One formatted output
1. Enter name, age, job, hobby.
Output:---------------info of Mary------------------
Name:mary
Age:18
Job:teacher
Hobbie:sing
----------------------End-------------------------
Eg:name = input ("Name:")
Age = Input ("Age:")
Job = Inut ("Job:")
Hobby = input ("HOBBT:")
info = ""
----------------------------Info of%s---------------# Each%s is a placeholder, (name)
Name:%s #代表name
Age:%s #代表 age
Job:%s #代表 Job
Hobby:%s #代表 Hobbie
--------------------------------End----------------------
'% (name,name,age,job,hobbie) # This is the line that associates the preceding string with the variable following the parentheses
Print (info)
2.%s,%d
%s represents a string placeholder; Everything can be converted directly to a string, only "%s".)
%d represents a digit placeholder. (Only numbers can be entered, and the corresponding data must be of type int).
3. Data type conversions:
int (str) # string converted to int
STR (int) # int converted to string
4. "Percent" to indicate "%" in the string.
If a placeholder such as%s is used in a string, all% will become placeholders, so "%" in the string is required to represent "percent"
Note: If you do not use%s,%d placeholder in the string, you do not need to use it instead.
Eg:print ("My name is%s, I'm 22 years old, I learned 2% of python"% ' Mary ') # has% placeholder.
Print ("My name is Mary, I'm 22 years old, I've finished my Homework 100%") # no placeholder
Two basic operators
1. Arithmetic operations "plus", "minus", "multiply", "except", "modulus (take Out) [%]", "power [*]", "divisible [//] ".
The% modulo returns the remainder of the division a=10, B=20, then the result of the b%a output is 0;
* * Power to return a to the power of B a=10, b=20, then A**b is 10 of the 20-th square;
Take the integer portion of the returned quotient a=10, b=20, then 9//2 output result 4, 9.0//2.0 output result 4.0.
2. Comparison Operations
= = Equals (compares objects are equal); # a "=" is an assignment
! = does not equal (compares two objects are not equal);
<> does not equal (compares two objects are not equal);
> Greater than
< less than (all operators return 1 for True ==>true, 0 for false ==>false);
>= greater than or equal to
<= less than or equal to
3. Assignment operation (Set a = ten, b =20)
= Simple assignment operator c=a+b indicates that the result of the a+b operation is assigned to C;
+ = Addition Assignment operator C+=a is equivalent to C=c+a;
The-= Subtraction assignment operator c-=a is equivalent to c=c-a;
The *= multiplication assignment operator c*=a is equivalent to c=c*a;
The/= Division assignment operator C/=a is equivalent to c=c/a;
The%=-to-film assignment operator C% A is equivalent to c=c% A;
The **= power assignment operator C **= A is equivalent to C=C * * A;
= The integer-divisible assignment operator C//=a is equivalent to c=c//a.
4. Logical operation
and Boolean "and" if a is false, A and B returns false, otherwise it returns the calculated value of "B" ;
or boolean "or" if a is true, a or B returns true, otherwise it returns the calculated value of "B ";
Not Boolean "non" if a is true, not a returns Falseif a is flase, it returns TRUE.
Attention:
1. In the absence of () the not priority is higher than and, and the and priority is higher than or,
That is, the priority relationship is () > Not > and >or . The same priority is computed from left to right).
2. x or Y, X is True, value is True, X is False, value is y;
X and Y,x are true, the value is Y, X is false, and the value is x;
3. Not false is neither true nor false.
Three-coding problem
1. Interpreter
The PYTHON2 interpreter encodes the content with "ASCII";
The PYTHON3 interpreter encodes the content with "UTF-8".
2. Development of the coding system
ASCII (US standard Information Interchange code) 8 bit 1 byte extended use limited;
GBK (GBK compatible ASCII) 2 byte in China only
eg: letter a:0100 0001 # ASCII
Letter a:0000 0000 0100 0001 # GBK GB Code
Unicode (Universal Code) 4 byte wasted
UTF-8 (variable length) English 8 bit 1 byte
Chinese bit 3 byte
3. Unit conversions
8 bit = 1 byte
1024x768 byte = 1KB
1024x768 KB = 1MB
1024x768 MB = 1GB
1024x768 GB = 1TB
1024x768 TB = 1PB
......
Python Full Stack development * 02 Knowledge Point Summary * 180531