程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Overview of the list of Python Basics

編輯:Python

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 .


One 、 background

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 .


Two 、 Concept

1、 Definition of list

list (list) Is included 0 An ordered sequence of one or more elements , Belongs to the sequence type .

2、 Features of lists

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 .

3、 List creation

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 :

4、 Access to the list

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]

5、 Assignment of the list

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 :


3、 ... and 、 Reference resources

1、 Liao Xuefeng's official website 2、python Official website 3、Python Programming case tutorial


Four 、 summary

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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved