Operator and coding
1 .Input name, age, job, hobby.
Output: info of Mary
Name : Mary
Age : 18
Job : Teacher
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 #Representing name
Age : %s #Representing age
Job : %s #Representing job
Hobby : %s #Representing hobbie
——————————– end ———————-
”’% (name,name,age,job,hobbie) # The% of this line is to associate the preceding string with variables after parenthesis.
2. %s , %d
%s Represents the string placeholder; (anything can be directly converted to a string, only “%s”.)
%d It represents the digit placeholder. It can only input numbers, and the corresponding data must be int type.
3. Data type conversion:
int ( str ) # String conversion to int
str ( int ) # int Convert into a string
4. ” %% ” To represent the “%” in a string.
If you use a placeholder such as%s in a string, all of the% percent will become a placeholder, so you need to use “%%” to represent the “%” of the string.
Note: if there is no use of%s and%d in the string, no need to replace it.
eg : print(“My name is%s. I am 22 years old. I have learned 2%%’s Python%’Mary’.
print( “My name is Mary. I am 22 years old. My homework has been completed 100%.
Two basic operator
1. Arithmetical operation, “add”, “minus”. ” Take off (module) “.
% The remainder of the division is returned by a=10, b=20, and then the output of b%a is 0.
** The power of the second power returns to the B power of a, a=10, b=20, and then a**b is the 20 power of 10.
// The integer part of the return operator, a=10, b=20, 9, / 2 output result 4, 9 9 / / 2 output result 4.
2. Comparison operation
== It is equal to the number of objects.
!= It is not equal to two.
<> It is not equal to two.
> greater than
< All operators return 1, which is true ==> True, return 0 indicates false ==> False);
>= More than equal or equal to
<= Less than equal to or equal to
3. A = 10, B =20)
= The simple assignment operator c=a+b a+b indicates that the result of the operation of C is assigned to C.
+= The addition assignment operator c+=a is equivalent to c=c+a.
-= The subtractive assignment operator c-=a is equivalent to c=c-a.
*= The multiplicative assignment operator c*=a is equivalent to c=c*a.
/= The division assignment operator c /=a is equivalent to the c=c / A;
%= The assignment assignment operator c a a is equivalent to c=c% a;
**= The power assignment operator c, a = c=c, is equivalent to * c=c * * a;
//= The divide and conquer assignment operator c //=a is equivalent to c=c//a.
4. Logic operation
and Boolean a byFalse, a and bReturnFalse,Otherwise it returns” b “The value of the calculation;
or “Boolean”a byTrue, a or bReturn to True, otherwise it returns ” b “The value of the calculation;
not Booleana byTrue, not a ReturnFalse,Ifa byFlase,It returns to True.
Pay attention to
1. Without (), the not priority is higher than and, and and priority is higher than or.
That is: the priority relation is () > not > and >or . The same priority is calculated from the left to the right.
2. x or y , x For true, the value is true, X is false, the value is y;
x and y,x To be true, the value is y, X is false, and the value is x;
3. not The truth is not true, but it is not true.
Three coding problems
Python2The interpreter uses the “ASCII” to encode the content.
Python3The interpreter uses the “UTF-8” to encode the content.
2. Development of coding system
ASCII ( American standard information exchange code 8 bit 1 byte The expansion of use is limited;
GBK ( GBKCompatible ASCII) 16 bit 2 byte Only China
eg : The letter A:0100 0001 is ASCII
Alphabet A:0000 000001000001 GBK
Unicode ( Wan Guoma) 32 bit 4 byte Waste
UTF-8 (Variable length) 8 bit 1 byte
Chinese 24 bit 3 byte
3. Unit conversion
8 bit = 1 byte
1024 byte = 1KB
1024 KB = 1MB
1024 MB = 1GB
1024 GB = 1TB
1024 TB = 1PB