Output the data in the specified format to the standard console or the specified file object
1.1print()
print('Hello World')
1.2 Formatted output
Role: to simplify the procedure
a ='python'print('I love %s'%a)
Format symbol
Conversion
%c
character
%s
String
%d
Signed decimal integer
% u
Unsigned decimal integer
%O
Octal integer
%x
Hexadecimal integer (lowercase letter 0x)
%X
Hexadecimal integer (uppercase letter 0X)
%f
Floating point
%e
Scientific notation (lowercase'e')
%E
Scientific notation (uppercase "E")
%g
Shorthand for %f and %e
%G
Shorthand for %f and %E
1.3 Newline output:\n
If there is \n in the output, the following content will be displayed on the next line
print('123\nABC')
123
ABC
2. Enter
input()
Receive user keyboard input
a =input('请输入姓名:')print(a)
input() The input data are all string types
3. Operator
3.1 Arithmetic operators
Operator
description
Instance
+
plus
1+1=2
-
Less
1-2=-1
*
Multiply
2*3=6
/
except
2/2=1
//
Divide
7//2=3
%
Take the remainder
7%2=1
**
index
2**3, which is 2 to the 3rd power
In mixed operation, the order of precedence is: ** higher than * /% // higher than + -, in order to avoid ambiguity, it is recommended to use () to handle operator precedence.
When performing mixed operations on different types of numbers, integers will be converted into floating-point numbers for operations.
3.2 Assignment operator
Operator
description
Instance
=
Assignment operator
Assign the result on the right side of the = to the variable on the left a = 1+1, the value of a is 2
3.3 compound assignment operator
Operator
description
Instance
+=
Addition assignment operator
c+=a is equivalent to c = c+a
-=
Subtraction assignment operator
c-=a is equivalent to c=ca
*=
Multiplication assignment operator
c*=a is equivalent to c=c*a
/=
Division assignment operator
c/=a is equivalent to c=c/a
%=
Modulus assignment operator
c%=a is equivalent to c=c%a
**=
Power assignment operator
c**=a is equivalent to c=c**a
//=
Divide and Divide Assignment Operator
c//=a is equivalent to c=c//a
4. Data type conversion
Common data type conversion
function
Description
int(x [,base])
Convert x to an integer
float(x)
Convert x to a floating point number
complex(real [,imag])
Create a complex number, real is the real part and imag is the imaginary part
str(x)
Convert object x to string
repr(x)
Convert object x to expression string
eval(str)
Used to calculate valid Python expressions in a string and return an object