Python self-study first day learning summary

1. The suffixes of the basic
python files are


two execution methods of .py py
1.cmd--->python + .py file [windows]
For example: python D:\123.py
2. Enter the py interpreter: real-time input And get the result. The


general py file will start with #! /usr/bin/env python # -*- coding:utf8 -*- The meaning of the first sentence is to let you in the command line mode of linux, You don't need to enter the python prefix. When opening the .py file, through this sentence, you declare that you want to open the file with the software in the path; of course, when you enter the python prefix in the command line mode, The system will call python in the environment variable, so this sentence has no effect. The meaning of the second sentence is to tell py to call utf8 to interpret this file (for py2 version, the 3 version supports utf8 and other encodings by default) 2. Variables Variables can only be composed of letters , numbers, and underscores Special cases: 1. The variable name cannot start with a number 2. The variable name cannot be the same as the py system variable : a = 'a1' b = "a2" c = '''a3''' d = """a4"" " Additionally





















Strings also follow addition and multiplication , for example:
e = a+b+c+d
====>e = a1a2a3a4


f = c*5
====>f = a3a3a3a3a3


Fourth, operators ( refer to http: //www.runoob.com/python/python-operators.html )
1. Arithmetic operator
+ - * / #Addition          , subtraction, multiplication and division
4**2 = 16 #4 square
66 % 8 = 2 #remainder
66 // 8 = 8 #Quotient (retaining integers)


2. Comparison operator (returning bool value)
== #Equal          (not to be confused with assignment)
!= #Not equal to
> #Greater than
< #Less than
>=          #Greater than or equal to
<=          #Less than or equal to


3. Assignment operator

+= #Example (the same as below): c +=a ===> c = c+a
-=
*=
/=
%=
**=
//=


4. Bit operator
&:         The result is 1 when both the first number and the second number are 1, otherwise it is 0
|: or the first number or When the second number is 1, the result is 1
^: Or if the two numbers are different, they are 1, and the same is 0
~: Invert 0 to 1, 1 to 0
<<: Left shift All binary bits of the          operand are shifted to the left A number of bits, the number of bits to the right of << specifies the number of bits to move, the high bits are discarded, and the low bits are filled with 0.
>>: right shift 5. Logical operator (returns a bool value) and or not 6. Member operator (returns a bool value) in returns True if a value is found in the specified sequence, otherwise returns False not in if in the specified sequence Returns True if no value is found, otherwise returns False 7. Identity operator (returning bool value) is is is to determine whether two identifiers refer to an object, similar to id(x) == id(y) not is and Similar to above 8. Operator precedence















** Exponent (highest priority)
~ + - bitwise flip, unary plus and minus (the last two have methods named +@ and -@)
* / % // multiply, divide, modulo and divide
+ - addition subtraction >> << right shift, left shift operator & bit 'AND' ^ | bit operator < > >= <= comparison operator <> == != equal operator = %= /= //= -= += *= **= assignment operator is , not is identity operator in , not in member operator or , and logical operator, when there are multiple or and and in the same statement, the general interpreter It will be explained from front to back 5. Types of numbers Python3 supports int, float, bool, complex (complex number)





                        
        

        



There is no bool type in version 2

6. Basic data types

numbers, strings, lists, tuples, dictionaries, booleans

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728239&siteId=291194637