Full-stack python development-Day4 list, python development-day4
Full-stack python development-Day4 listI. First, expand the learning list based on the following points:
#1: Basic use 1 Purpose 2 definition method 3 common operations + Built-in method #2: this type of Summary 1 stores one value or multiple values. Only one value can be saved and multiple values can be saved. What type can a value be? 2 ordered or unordered 3 variable or immutable !!! Variable: The value changes, and the id remains unchanged. Variable = non-hash !!! Immutable: The value changes, and the id changes. Immutable = hash
2. Start learning based on the above questions
# First, the basic purpose of the List: Multiple equipment, multiple hobbies, multiple courses, multiple girlfriends, etc. # definition: [] can have multiple values of any type, separate my_girl_friends = ['Alex ', 'wupeiqi', 'yuanhao',] # Essence my_girl_friends = list ([...]) or l = list ('abc') # preferred operations: #1. Access by index (forward access + reverse access ): you can also save it by name = ['Alex ', 'wupeiqi', 'yuanhao', 'qianduoduo ', 'qianzeliang '] name [0] # The value is alex name [0] = 'manyqian' print (name) # The value is ['manyqian ', 'wupeiqi', 'yuanhao ', 'qianduoduo', 'qianzeliang '] #2. Slice (regardless of tail, step size) name = ['Alex', 'wupeiqi ', 'yuanhao', 'qianduoduo ', 'qianzeliang '] name [0: 2] # The value is ['Alex', 'wupeiqi ', 'yuanhao'] name [0: 5] # The value is ['Alex', 'yuanhao ', 'qianzeliang '] Step Size is one step by default #3. Length name = ['Alex', 'wupeiqi ', 'yuanhao', 'qianduoduo', 'qianzeliang'] len (name) #5 #4. member operations in and not inname = ['Alex ', 'wupeiqi', 'yuanhao', 'qianduoduo ', 'qianzeliang '] 'Alex' in name # value: True 'duoduo' in name # value: Flase 'duoduo' in name # value: True #5. append name = ['Alex ', 'wupeiqi', 'yuanhao', 'qianduoduo', 'qianzeliang '] name. append ('duoduo') print (name) # The value is ['Alex ', 'wupeiqi', 'yuanhao', 'qianduoduo', 'qianzeliang ', 'duoduo'] name. append ('chunjiduo ') print (name) # The value is ['Alex', 'wupeiqi ', 'yuanhao', 'qianduoduo', 'qianzeliang', 'duoduo ', 'chunjiduo '] #6. Delete name = ['Alex', 'wupeiqi ', 'yuanhao', 'qianduoduo', 'qianzeliang'] name. remove ('Alex ') print (name) # The value is ['wupeiqi', 'yuanhao', 'qianduoduo', 'qianzeliang'] name. pop () # The default value is-1 print (name) # The value is ['wupeiqi ', 'yuanhao', 'qianduoduo'] name. pop (0) # You can also specify the index print (name) # value of the List as ['yuanhao', 'qianduoduo'] the difference between the pop () method and the remove () method: name = ['Alex ', 'wupeiqi', 'yuanhao', 'qianduoduo', 'qianzeliang '] print (name. remove ('Alex ') # The value is Noneprint (name. pop () # The value is 'qianzeliang '#7. Loop name = ['Alex', 'wupeiqi ', 'yuanhao', 'qianduoduo ', 'qianzeliang '] for I in name: print (I) # output alex wupeiqi yuanhao qianduoduo qianzeliangcount = 0 while count <5: print (name [count]) # output alex wupeiqi yuanhao qianduoduo qianzeliang count + = 1 in sequence
Iii. Summary of the list: 1. Multiple values can be saved. What type can the values be? 2. Order. 3. Variable: The value changes, and the id remains unchanged. Variable = non-hash 4. Integer and floating point type
# Integer int: age, grade, ID card number, QQ number, and other integer-related definitions: age = 10 # essential age = int (10) # floating point float: salary, height, weight, salary = 3000.3 # essential salary = float (3000.3) # binary, decimal, octal, hexadecimal
The most common Conversions
Bin (2) binary, Oct (8) octal, hex (16) hexadecimal
Other numeric types (learn more)
# Long Integer (understanding) in python2 (python3 does not have the concept of long integer): >>> num = 2L >>> type (num) <type 'long'> # plural (knowledge) >>> x = 1-2j >>> x. real 1.0> x. imag-2.0
V. Data OperationsArithmetic Operation:
PS: The modulo can be used to determine the parity.
Comparison:
Assignment operation:
Logical operation:
Member calculation:
Identity calculation: