1Run
1.1 run the python command directly in the command line
1.2 compile the X. py file and run it using python X. py.
2Variable
Print can be followed by multiple outputs
No need to specify the data type. You can assign a value directly after the variable name.
Then use
Print type (variable name) can print the Data type of the variable name
Int float str bool...
------------------------- Codearea ------------------------------------
>>> A = True
>>> Printtype ()
>>>
------------------------- Codearea ------------------------------------
Variables do not need to be declared or deleted. They can be recycled directly.
Type (): query data type
3SequenceSequence
It is a set of ordered elements and objects.
A sequence can contain one or more elements, or has no elements. It is similar to an array in C.
Basic data types can all be used as sequence elements.
(PS: md, this has a bug that is always blocked when connected.
The sequence is divided into: tuple-value table/tuples, list-table
Difference: Once created, each element of the tuple cannot be changed, and each element of the list can be changed.
Example: when you try to change the tuple element, the following error occurs:
------------------------- Codearea ---------------------------------------
>>> S1 [1] = 3
Traceback (mostrecent call last ):
File" ", Line 1, in
TypeError: 'tuple' object does not support item assignment
------------------------- Codearea ---------------------------------------
The sequence of one element can be an element of another sequence.
Element reference:
The following table and C both start from 0. Because the list element is variable, the corresponding value can be assigned as the code above.
Range reference: [lower limit: Upper Limit: Step Size]
------------------------- Codearea ------------------------------------------------------------
>>> Prints1 [: 5] # From start to subscript 4 (the element of subscript 5 is not included)
>>> Prints1 [2:] # From subscript 2 to the end
>>> Prints1 [] # From subscript 0 to subscript 4 (subscript 5 is not included), take an element every 2 (subscript is 0, 2, 4)
>>> Print s1 [2: 0:-1] # From subscript 2 to subscript 1
>>> Prints1 [-1] # the last element of the sequence
>>> Prints1 [-3] # The last and third elements of the sequence
------------------------- Codearea -------------------------------------------------------------
If the upper limit is specified during range reference, the upper limit is not included.
A string is a special tuples that can be used to perform operations on tuples.
------------------------- Codearea -------------------------------------------------------------
>>> Str = 'abcdefg'
>>> Printstr [2: 5]
Cde
>>>
------------------------- Codearea -------------------------------------------------------------