Full-stack python development-Day4 list, python development-day4

Source: Internet
Author: User

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:

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.