当前位置:网站首页>Python basic syntax variables

Python basic syntax variables

2020-11-08 10:54:09 Autumn maple

python

 

 

 

python What can be done ?

 

 

 

python Characteristics

(1) Grammar is simple , Easy to learn and use
(2) object-oriented programming
(3) Cross platform , It's portable
(4) Modular development , Rich in functions
(5) It has good expansibility

Data labels : Variable

 

Declare variables
    1. Need to pay attention to :
      The first character cannot be a number ;
      The identifier cannot have spaces ;
      Identifier cannot be associated with Python The key words are ;
      Case sensitive .
      Variable name : Use capital letters , Lowercase letters , Numbers , Underline , Chinese characters and other characters are combined to name .

 

 

 

 

 

 2. assignment :python The assignment sign of is equal sign “=” , The purpose of assignment is to associate names with values ., for example :

 

 

  The assignment operation does not change any value on the right :

Operators and Expressions

Operators include :

One 、 Arithmetic operator :

 

 

  The addition operator :

 

 

 

Running results :
sum1=107, sum2=22.50

Subtraction operators :

 

 

  Running results :
-45 , 83.5
Be careful , Use alone + It's invalid , It doesn't change the value of the number , for example :

 

 

 

Running results :
45 , -83.5

Multiplication operators

Please look at the code. :

 

 

 

Running results :
100 , 69.0

/ and // Division operator

 

 

 / Means common division , The result calculated by this method is the same as that in mathematics .
// To divide or divide , Keep only the integer part of the result , Give up the decimal part ; The point is to just throw away the fraction , Rather than rounding .
Example :

 

 

Calculation results
23/5 = 4.6
23//5 = 4
23.0//5 = 4.0

25/5 = 5.0
25//5 = 5
25.0//5 = 5.0

12.4/3.5 = 3.542857142857143
12.4//3.5 = 3.0

Two 、 Comparison operator :

 

3、 ... and 、 Assignment operator :

 

 

版权声明
本文为[Autumn maple]所创,转载请带上原文链接,感谢