About bloggers : Former Internet manufacturer tencent staff , Network security giant Venustech staff , Alibaba cloud development community expert blogger , WeChat official account java Quality creators of basic notes ,csdn High quality creative bloggers , Entrepreneur , Knowledge sharers , Welcome to your attention , give the thumbs-up , Collection .
Python Is an easy to learn 、 Powerful programming language . It provides an efficient high-level data structure , It's also a simple and effective way of object-oriented programming .Python Elegant grammar and dynamic typing and the essence of interpretive language , Make it an ideal language for scripting and rapid application development on most platforms . Now let's introduce python Overview of the list and related knowledge .
list (list) Is included 0 An ordered sequence of one or more elements , Belongs to the sequence type .
The length and content of the list are variable , You are free to add elements to the list 、 Delete or replace . The list has no length limit , Element types can be different , Can contain both integers 、 The set of real Numbers 、 String and other basic types , It could be a list 、 Tuples 、 Dictionaries 、 Collection and other custom types of objects , Very flexible to use .
The way to create a list is simple , Just enclose the different elements separated by commas in square brackets .
animal = ['elephant', 'monkey', 'snake', 'tiger']
print(animal)
give the result as follows :
Just like the index of a string , The list index is also from 0 At the beginning . We can access the values in the list by subscript index .
animal[0]
Unlike integers and strings , A list deals with a set of data , therefore , Lists must be generated by explicit data assignments , Simply assigning a list to another will not generate a new list object , Just generate a new reference to the original list . example : Assignment and reference of list .
stu_1 = ['001', 'Wangwu', 98] # Create a list using data assignment stu_1
stu_2 = stu_1 # stu_2 yes stu_1 Application of corresponding data ,stu_2 Does not contain real data
print(stu_1, stu_2) # Output stu_1 and stu_2
stu_1[0] = '002' # Modifying elements stu_1[0] The value of is '002'
print(stu_1, stu_2) # Output stu_1 and stu_2
give the result as follows :
You can also use list() Function to string 、range object 、 Objects such as tuples are converted to lists . Its grammatical form is list(obj), among obj For the object to be converted .
a = list('hello world')
b = list(range(1, 10, 2))
print(a)
print(b)
give the result as follows :
1、 Liao Xuefeng's official website 2、python Official website 3、Python Programming case tutorial
The above is about Python Knowledge of the advantages and disadvantages of language , You can refer to it , Relevant knowledge will be continuously updated later , Make progress together .