- # Starting the Hello world in python is quite simple.
- #! User/bin/ENV python3 # This line is shebang, used to indicate which interpreter is used for execution. If yes, it must be in the first line of the program
- Print ("Hello world! ") # Hello world!
- Print (123, "123") #123 123
- Print (1 + 2) #3
- Route = 866
- Print (route, type (route) #866 <class 'int'> type is used to obtain the data type
-
- Route = "North" # variables in python can be assigned at will without worrying about its type. Of course, it does not need to be declared.
- Print (route, type (route) # North <class 'str'>
- X = ["one", "two", "three", "four"]
- # Create a list object. I can understand it as an array.
- Print (X [0], X [1], X [3]) # One Two four
- # The list can be used like an array. The index is a set of consecutive numbers starting with 0.
-
- X. append ("five") # although it is similar to an array, it is indeed an object and can easily perform some operations
- Print (x) # ['one', 'two', 'three ', 'four', 'five']
-
- List. append (x, "Six") # You can also use the class to perform related operations.
- Print (x) # ['one', 'two', 'three ', 'four', 'five', 'six']
-
- X. insert (0, "zero") # other methods can be used. The first parameter is the index.
- Print (x) # ['zero ', 'one', 'two', 'three', 'four ', 'five', 'six']
- X. Remove ("six") # You can also delete related list items.
- X. Remove ("zero") # The parameter specifies the value to be deleted.
- Print (x) # ['one', 'two', 'three ', 'four', 'five']
-
- X [1] = 2 # You can still assign values to a specified list item like an array, and do not need to pay attention to its type.
- Print (x) # ['one', 2, 'three ', 'four', 'five']
- # Identity Operators
- A = ["one", 1, none]
- B = ["one", 1, none] # declare two identical lists
- Print (A is B) # False
- B = A # assign values to direct the two objects to the same object
- Print (A is B) # True
- # The is operator is the memory address to which two objects are referenced, so it is usually faster.
-
- A = "something"
- B = none
- Print (A is none, B is not none)
- # False false can also be compared with the same empty object none (it should be noted that python is case-sensitive none and none are different)
-
-
- # Comparison Operators
- A = 2
- B = 6
- Print (A = B, A <= B, A> = B,! = B, A> B, A <B)
- # False True False true
- # There is nothing to pay attention to. It is similar to any programming language.
- # Link comparison
- A = 5
- Print (0 <= A <= 10) # True
-
- # Comparison between computation and identity Computation
- A = "paths"
- B = "paths"
- Print (A is B) # False
- Print (A = B) # True
- # Here we can see the difference between the reference value
-
- # Member operators
- P = (4, "frog", 9,-33, 9, 2)
- # Create a list object that can also be enclosed in parentheses
- Print (2 in P) # True
- Print ("dog" not in P) # True
-
- # Logical operators
- Two = 2
- Five = 5
- Zero = 0
- Print (two and five) #5
- Print (five and two) #2
- Print (zero and five) #0
- Print (two and zero) #0
- Print (five or two) #5
- Print (two or five) #2
- Print (zero or five) #5
- # There is no description in the book, but if there are two non-zero numbers and, the return operator is followed
- # If there are two non-zero numbers or, the first one is returned.
Unfinished (to be continued)