Variables, operators and input and output in Python

Insert picture description here

Variables in Python

What is a variable

A variable is an address in memory, and a fixed string is used to represent this address. This string is a variable, and the object assignment is actually a reference to the object

Variable naming

Variables are composed of letters, numbers, and underscores. They cannot start with a number. In
Pyhton, the variable does not need to specify the type when it is defined. When the variable is used, the variable must be assigned a value.

Operator

Five basic number types supported by python
float (floating point number)
complex (complex number)
int (signed integer)
long (long integer)
bool (Boolean value)

Arithmetic operators: +,-, *, /, **,%, //
where stands for multiplication, / stands for division
**: power
%: take remainder
//: round

Base

十进制	1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16
二进制	0.1.10.11.100.101.110.111.1000.1001…
八进制	1.2.3.4.5.6.7.10.11.12.13.14.15.16.17.20
十六进制	1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.10

Decimal conversion

n represents a number
bin(n): decimal to binary
oct(n): decimal to octal
hex(n): decimal to hexadecimal

Relational operator

<<=! = ==
greater than less than less than or equal to equal to not equal judgment
logical operators
and or not
with non-

Data input and output

Input
input (string that needs to be entered)
int (input (value that needs to be entered))

The output
print is a function in python3.X
and just a keyword in python2.X

Exercise 1 Find the average score of three subjects

Insert picture description here

Exercise 2 Temperature converter

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42958401/article/details/108790540