Danh sách () trong Python là gì?

Danh sách Python giống như các mảng có kích thước động, được khai báo bằng các ngôn ngữ khác (vector trong C++ và ArrayList trong Java). Nói một cách đơn giản, danh sách là một tập hợp các thứ, được đặt trong [ ] và được phân tách bằng dấu phẩy.  

Danh sách là một kiểu dữ liệu trình tự được sử dụng để lưu trữ bộ sưu tập dữ liệu. Tuples và String là các kiểu dữ liệu chuỗi khác

Ví dụ về danh sách trong Python

Ở đây chúng tôi đang tạo Danh sách Python bằng []

Python3




List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
0
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
3
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
5
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
3
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
0

đầu ra

["Geeks", "for", "Geeks"]

Danh sách là các thùng chứa đơn giản nhất là một phần không thể thiếu của ngôn ngữ Python. Các danh sách không cần phải luôn đồng nhất, điều này khiến nó trở thành công cụ mạnh nhất trong Python. Một danh sách có thể chứa các Kiểu dữ liệu như Số nguyên, Chuỗi, cũng như Đối tượng. Danh sách có thể thay đổi và do đó, chúng có thể được thay đổi ngay cả sau khi tạo

Tạo một danh sách trong Python

Danh sách trong Python có thể được tạo bằng cách đặt chuỗi bên trong dấu ngoặc vuông[]. Không giống như Bộ, danh sách không cần chức năng tích hợp để tạo danh sách.  

Ghi chú. Không giống như Bộ, danh sách có thể chứa các phần tử có thể thay đổi.   

ví dụ 1. Tạo một danh sách trong Python

Python3




Accessing a element from the list
Geeks
Geeks
1

Accessing a element from the list
Geeks
Geeks
2

 

Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Accessing a element from the list
Geeks
Geeks
6

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
9
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from a Multi-Dimensional list
For
Geeks
5

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2_______21_______9
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
3
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing element using negative indexing
Geeks
For
7
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

0
3
3

0
3
4

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
3
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
0
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
3_______0_______8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
6
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks

Sự phức tạp để tạo danh sách

Thời gian phức tạp. Ô(1)

Độ phức tạp không gian. Trên)

ví dụ 2. Tạo danh sách có nhiều phần tử riêng biệt hoặc trùng lặp

Một danh sách có thể chứa các giá trị trùng lặp với các vị trí riêng biệt của chúng và do đó, nhiều giá trị khác biệt hoặc trùng lặp có thể được chuyển thành một chuỗi tại thời điểm tạo danh sách

Python3




Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
0

Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
1

Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
2

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04_______0_______4_______71_______10_______2_______ 8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
16
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
0

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
23

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
24

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
36
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32_______0_______8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
44
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']

Truy cập các phần tử từ Danh sách

Để truy cập các mục danh sách, hãy tham khảo số chỉ mục. Sử dụng toán tử chỉ mục [ ] để truy cập một mục trong danh sách. Chỉ số phải là một số nguyên. Danh sách lồng nhau được truy cập bằng cách sử dụng chỉ mục lồng nhau.  

ví dụ 1. Truy cập các phần tử từ danh sách

Python3




Accessing a element from the list
Geeks
Geeks
1

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
51

 

Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
0

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
53

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
3
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
0
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
3_______0_______8

 

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
63

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
64

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
67
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

Đầu ra

Accessing a element from the list
Geeks
Geeks

ví dụ 2. Truy cập các phần tử từ danh sách đa chiều

Python3




Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
81

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
82

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
85
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
36
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
89
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
91

 

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
92

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
93

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
94

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
97
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
04
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
04
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
2
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

Đầu ra

Accessing a element from a Multi-Dimensional list
For
Geeks

lập chỉ mục tiêu cực

Trong Python, các chỉ mục chuỗi âm biểu thị các vị trí từ cuối mảng. Thay vì phải tính offset như trong List[len(List)-3], chỉ cần viết List[-3] là đủ. Lập chỉ mục phủ định có nghĩa là bắt đầu từ cuối, -1 đề cập đến mục cuối cùng, -2 đề cập đến mục cuối cùng thứ hai, v.v.

Python3




Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
36
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32_______0_______8

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
32

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
33

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
36
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
38

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
43
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
46

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
43
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

Đầu ra

Accessing element using negative indexing
Geeks
For

Sự phức tạp khi truy cập các phần tử trong Danh sách

Thời gian phức tạp. Ô(1)

Độ phức tạp không gian. Ô(1)

Lấy kích thước của danh sách Python

Python len() được sử dụng để lấy độ dài của danh sách

Python3




Accessing a element from the list
Geeks
Geeks
3

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
55
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Accessing a element from the list
Geeks
Geeks
6

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
60
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
61

 

Accessing a element from a Multi-Dimensional list
For
Geeks
5

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
63
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2_______21_______9
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
3
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
60
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
75

Đầu ra

0
3

Lấy đầu vào của danh sách Python

Chúng ta có thể lấy đầu vào của một danh sách các phần tử là chuỗi, số nguyên, dấu phẩy, v.v. Nhưng cái mặc định là một chuỗi

Danh sách () trong Python là gì?

ví dụ 1.  

Python3




List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
76

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
77

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
78

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
79

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
80

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
81
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
83
Accessing a element from the list
Geeks
Geeks
8_______0_______85
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
87

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
88
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
90

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
93
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
94
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
95

đầu ra

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']

ví dụ 2

con trăn




List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
96

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
97
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
99
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
83
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
03
Accessing a element from the list
Geeks
Geeks
04

Accessing a element from the list
Geeks
Geeks
05

Accessing a element from the list
Geeks
Geeks
06

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
88
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Accessing a element from the list
Geeks
Geeks
09
Accessing a element from the list
Geeks
Geeks
8_______10_______11
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
99
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
83
Accessing a element from the list
Geeks
Geeks
16

Accessing a element from the list
Geeks
Geeks
17

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
95

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
93
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
94

đầu ra

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]

Để biết thêm xem cái này

Thêm phần tử vào danh sách Python

Phương pháp 1. Sử dụng phương thức append()

Các phần tử có thể được thêm vào Danh sách bằng cách sử dụng hàm append() tích hợp sẵn. Mỗi lần chỉ có thể thêm một phần tử vào danh sách bằng cách sử dụng phương thức append(), để thêm nhiều phần tử bằng phương thức append(), các vòng lặp được sử dụng. Các bộ dữ liệu cũng có thể được thêm vào danh sách bằng cách sử dụng phương thức append vì các bộ dữ liệu là bất biến. Không giống như Bộ, Danh sách cũng có thể được thêm vào danh sách hiện có bằng cách sử dụng phương thức append()

Python3




Accessing a element from the list
Geeks
Geeks
1

Accessing a element from the list
Geeks
Geeks
24

 

Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Accessing a element from the list
Geeks
Geeks
6

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
31
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from the list
Geeks
Geeks
37

Accessing a element from the list
Geeks
Geeks
38

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
40
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
40
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
40
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
53
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from the list
Geeks
Geeks
59

Accessing a element from the list
Geeks
Geeks
60

Accessing a element from the list
Geeks
Geeks
61
Accessing a element from the list
Geeks
Geeks
62
Accessing a element from the list
Geeks
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
Accessing a element from the list
Geeks
Geeks
69

Accessing a element from the list
Geeks
Geeks
70_______10_______4
Accessing a element from the list
Geeks
Geeks
72

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
75
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from the list
Geeks
Geeks
81

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
83
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
Accessing a element from the list
Geeks
Geeks
04

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
90
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from the list
Geeks
Geeks
96

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
63
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
36_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
05

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
08
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]

Sự phức tạp khi thêm các phần tử trong một Lists(append() method)

Thời gian phức tạp. Ô(1)

Độ phức tạp không gian. Ô(1)

Phương pháp 2. Sử dụng phương thức chèn()

Phương thức append() chỉ có tác dụng khi thêm phần tử vào cuối List, để thêm phần tử vào vị trí mong muốn thì sử dụng phương thức insert(). Không giống như append() chỉ nhận một đối số, phương thức insert() yêu cầu hai đối số (vị trí, giá trị).  

Python3




Accessing a element from the list
Geeks
Geeks
1

Accessing a element from the list
Geeks
Geeks
24

Accessing a element from a Multi-Dimensional list
For
Geeks
16

Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from a Multi-Dimensional list
For
Geeks
37

Accessing a element from a Multi-Dimensional list
For
Geeks
38

Accessing a element from a Multi-Dimensional list
For
Geeks
39

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
41
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
44
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
41
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
54
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
0

Sự phức tạp khi thêm các phần tử trong một Lists(insert() method)

Thời gian phức tạp. TRÊN)

Độ phức tạp không gian. Ô(1)

Phương pháp 3. Sử dụng phương thức mở rộng()

Ngoài các phương thức append() và insert(), còn một phương thức nữa để cộng phần tử là Extend(), phương thức này dùng để thêm nhiều phần tử cùng lúc vào cuối danh sách

Ghi chú. Các phương thức append() và expand() chỉ có thể thêm các phần tử vào cuối

Python3




Accessing a element from the list
Geeks
Geeks
1

Accessing a element from the list
Geeks
Geeks
24

 

Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from a Multi-Dimensional list
For
Geeks
82

Accessing a element from a Multi-Dimensional list
For
Geeks
83

Accessing a element from a Multi-Dimensional list
For
Geeks
84

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
86
Accessing a element from a Multi-Dimensional list
For
Geeks
87
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
91
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
3

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
95
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
1

Sự phức tạp khi thêm các phần tử trong một Lists(extend() method)

Thời gian phức tạp. TRÊN)

Độ phức tạp không gian. Ô(1)

Đảo ngược danh sách

Một danh sách có thể được đảo ngược bằng cách sử dụng phương thức reverse() trong Python

Python3




Accessing element using negative indexing
Geeks
For
01

Accessing element using negative indexing
Geeks
For
02_______0_______1 ______0_______2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6_______0_______4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
15
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
17_______0_______8

Accessing element using negative indexing
Geeks
For
19

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing element using negative indexing
Geeks
For
21

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
2

Xóa phần tử khỏi danh sách

Phương pháp 1. Sử dụng phương thức remove()

Có thể xóa các phần tử khỏi Danh sách bằng cách sử dụng hàm remove() tích hợp nhưng Lỗi sẽ phát sinh nếu phần tử không tồn tại trong danh sách. Phương thức Remove() chỉ xóa một phần tử tại một thời điểm, để xóa một loạt phần tử, trình vòng lặp được sử dụng. Phương thức remove() xóa mục đã chỉ định

Ghi chú. Phương thức xóa trong Danh sách sẽ chỉ xóa lần xuất hiện đầu tiên của phần tử được tìm kiếm

ví dụ 1

Python3




Accessing a element from the list
Geeks
Geeks
1

Accessing element using negative indexing
Geeks
For
23

 

Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4

Accessing element using negative indexing
Geeks
For
40
Accessing element using negative indexing
Geeks
For
41
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
87
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
45
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
9
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
49
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
44
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing element using negative indexing
Geeks
For
61

Accessing element using negative indexing
Geeks
For
62

Accessing a element from the list
Geeks
Geeks
4
Accessing element using negative indexing
Geeks
For
64
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing element using negative indexing
Geeks
For
64
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing element using negative indexing
Geeks
For
73
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
3

ví dụ 2

Python3




Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4

Accessing element using negative indexing
Geeks
For
40
Accessing element using negative indexing
Geeks
For
41
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
87
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
45
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
9
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
49
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
44
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

Accessing element using negative indexing
Geeks
For
61

0
3
09

Accessing a element from the list
Geeks
Geeks
61
Accessing a element from the list
Geeks
Geeks
62
Accessing a element from the list
Geeks
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
Accessing a element from the list
Geeks
Geeks
69

Accessing a element from the list
Geeks
Geeks
70_______10_______4
0
3
21

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
0
3
24
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
4

Sự phức tạp khi xóa các phần tử trong một Lists(phương thức remove())

Thời gian phức tạp. TRÊN)

Độ phức tạp không gian. Ô(1)

Phương pháp 2. Sử dụng phương thức pop()

Hàm pop() cũng có thể được sử dụng để xóa và trả về một phần tử khỏi danh sách, nhưng theo mặc định, hàm này chỉ xóa phần tử cuối cùng của danh sách, để xóa một phần tử khỏi một vị trí cụ thể của Danh sách, chỉ số của phần tử được truyền

Python3




Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04_______0_______4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

 

0
3
43

0
3
44

Accessing a element from the list
Geeks
Geeks
4
0
3
46

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
0
3
49
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

0
3
55

0
3
56

0
3
44

Accessing a element from the list
Geeks
Geeks
4
0
3
59
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
0
3
64
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
5

Sự phức tạp khi xóa các phần tử trong phương thức Lists(pop())

Thời gian phức tạp. O(1)/O(n) (O(1) để xóa phần tử cuối cùng, O(n) để xóa phần tử đầu tiên và ở giữa)

Độ phức tạp không gian. Ô(1)

Cắt một danh sách

Chúng ta có thể lấy các chuỗi con và danh sách con bằng cách sử dụng một lát cắt. Trong Danh sách Python, có nhiều cách để in toàn bộ danh sách với tất cả các phần tử, nhưng để in một dải phần tử cụ thể từ danh sách, chúng ta sử dụng thao tác Slice.  

Thao tác lát cắt được thực hiện trên Danh sách bằng cách sử dụng dấu hai chấm (. ).  

Để in các phần tử từ đầu đến một phạm vi, hãy sử dụng

[. Mục lục]

Để in các phần tử từ mục đích sử dụng cuối

[. -Mục lục]

Để in các phần tử từ một Chỉ mục cụ thể cho đến khi sử dụng hết

[Mục lục. ]

Để in toàn bộ danh sách theo thứ tự ngược lại, hãy sử dụng

[. -1]

Lưu ý – Để in các thành phần của Danh sách từ phía sau, hãy sử dụng Chỉ mục phủ định.  

Danh sách () trong Python là gì?
 

TÌM HIỂU CẮT DANH SÁCH

  • pr[0] truy cập mục đầu tiên, 2
  • pr[-4] truy cập mục thứ tư từ cuối, 5
  • pr[2. ] truy cập [5, 7, 11, 13], danh sách các mục từ thứ ba đến cuối cùng
  • trước [. 4] truy cập [2, 3, 5, 7], danh sách các mục từ thứ nhất đến thứ tư
  • pr[2. 4] truy cập [5, 7], danh sách các mục từ thứ ba đến thứ năm
  • pr[1. 2] truy cập [3, 7, 13], các mục thay thế, bắt đầu từ mục thứ hai

Python3




Accessing a element from the list
Geeks
Geeks
1

Accessing element using negative indexing
Geeks
For
23

 

Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
0
3
76
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
82
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
84
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
86
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4

Accessing element using negative indexing
Geeks
For
40
0
3
89
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
91
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
76
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
82
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
84
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
11

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
12

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
13_______0_______1
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
18
Accessing a element from a Multi-Dimensional list
For
Geeks
87
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
23
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

 

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
27

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
28

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
13_______0_______1
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
34

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
37

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
38
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
39
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

 

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
43

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
44

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
13_______0_______1
Accessing a element from the list
Geeks
Geeks
4
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
48

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
51
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
6

Chỉ số phủ định Cắt lát danh sách

Python3




Accessing a element from the list
Geeks
Geeks
3

Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
0
3
76
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
82
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
84
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
86
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4

Accessing element using negative indexing
Geeks
For
40
0
3
89
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
91
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
76
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
78
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
82
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
0
3
84
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
94

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
95

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
13_______0_______1
Accessing a element from the list
Geeks
Geeks
4
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
99_______0_______43
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
05
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

 

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
11

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
10

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
13_______0_______1
Accessing a element from the list
Geeks
Geeks
4
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
2
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
43
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
18
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
43
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
23
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

 

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
27

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
12

Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
13_______0_______1
Accessing a element from the list
Geeks
Geeks
4
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
32_______0_______43
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Accessing a element from the list
Geeks
Geeks
8
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
38
Accessing a element from a Multi-Dimensional list
For
Geeks
0

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
7

Danh sách hiểu

Khả năng hiểu danh sách Python được sử dụng để tạo danh sách mới từ các lần lặp khác như bộ dữ liệu, chuỗi, mảng, danh sách, v.v. Việc hiểu danh sách bao gồm các dấu ngoặc chứa biểu thức, được thực thi cho từng phần tử cùng với vòng lặp for để lặp qua từng phần tử.  

cú pháp

danh sách mới = [ biểu thức (phần tử) cho phần tử trong danh sách cũ nếu điều kiện ]

Thí dụ.  

Python3




Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
42

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
43

 

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
44

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
45

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
46
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
48
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
49
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
49
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
Accessing a element from the list
Geeks
Geeks
61
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
53
Accessing a element from the list
Geeks
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
49
Accessing a element from a Multi-Dimensional list
For
Geeks
0
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
61
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
53
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
63
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
8

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
70

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
8

Để hiểu rõ hơn, đoạn mã trên tương tự như sau.  

Python3




Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
71

Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
46______0_______1
Accessing a element from the list
Geeks
Geeks
6

 

Accessing a element from the list
Geeks
Geeks
61
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
53
Accessing a element from the list
Geeks
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
4
Accessing element using negative indexing
Geeks
For
49
Accessing a element from the list
Geeks
Geeks
69

Accessing a element from the list
Geeks
Geeks
70_______63_______61
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
53_______63_______63
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
1
Initial blank List: 
[]

List after Addition of Three elements: 
[1, 2, 4]

List after Addition of elements from 1-3: 
[1, 2, 4, 1, 2, 3]

List after Addition of a Tuple: 
[1, 2, 4, 1, 2, 3, (5, 6)]

List after Addition of a List: 
[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
6
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
18

Accessing element using negative indexing
Geeks
For
40
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
94
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
49
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
49
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
8
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
9
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
70

Đầu ra

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
8

Tham khảo các bài viết dưới đây để biết thông tin chi tiết về List Comprehension

  • Hiểu và cắt danh sách Python
  • Hiểu danh sách lồng nhau trong Python
  • Hiểu danh sách và ord() trong Python

Ví dụ cơ bản về Danh sách Python

  • Chương trình Python để trao đổi các phần tử đầu tiên và cuối cùng trong một danh sách
  • Chương trình Python hoán đổi hai phần tử trong danh sách
  • Python – Hoán đổi các phần tử trong danh sách Chuỗi
  • con trăn. Các cách để tìm độ dài của danh sách
  • Tối đa hai số trong Python
  • Tối thiểu hai số trong Python

Để thực hành thao tác danh sách cơ bản, vui lòng đọc bài viết này – Danh sách chương trình Python

Liệt kê các phương thức

FunctionDescriptionAppend()Thêm một phần tử vào cuối danh sáchExtend()Thêm tất cả các phần tử của một danh sách vào một danh sách khácInsert()Chèn một mục vào chỉ mục đã xác địnhRemove()Xóa một mục khỏi danh sáchClear()Xóa tất cả các mục khỏi listIndex()

Để biết thêm, hãy tham khảo bài viết này – Python List methods

Các hoạt động được đề cập ở trên tự sửa đổi danh sách

Các chức năng tích hợp với Danh sách

FunctionDescriptionreduce() áp dụng một hàm cụ thể được truyền trong đối số của nó cho tất cả các thành phần danh sách lưu trữ kết quả trung gian và chỉ trả về giá trị tổng cuối cùngsum()Tổng các số trong listord()Trả về một số nguyên biểu thị điểm mã Unicode của giá trị đã cho . nếu danh sách trống, trả về falselen()Trả về độ dài của danh sách hoặc kích thước của đối tượng lắng nghe()Trả về đối tượng liệt kê của listaccumulate()áp dụng một hàm cụ thể được truyền trong đối số của nó cho tất cả các phần tử danh sách trả về một danh sách chứa phần tử trung gian

Xem qua các bài báo gần đây về Danh sách

Liên kết hữu ích.  

  • Các bài báo gần đây về Danh sách Python
  • Hướng dẫn Python
  • Câu hỏi trắc nghiệm
  • Tất cả các bài viết trong Danh mục Python

{ "@định nghĩa bài văn". “https. //lược đồ. tổ chức/”, “@type”. “Bài báo”, “mainEntityOfPage”. { "@loại". “Trang web”, “@id”. “https. //www. chuyên viên máy tính. org/python-list/” }, “tiêu đề”. “Danh sách Python”, “mô tả”. “Danh sách Python giống như các mảng có kích thước động, được khai báo bằng các ngôn ngữ khác (vector trong C++ và ArrayList trong Java). ", "hình ảnh". “https. //phương tiện truyền thông. chuyên viên máy tính. org/wp-content/uploads/List-Slicing. jpg”, “tác giả”. { "@loại". "Tên tổ chức". “GeeksforGeeks” }, “nhà xuất bản”. { "@loại". "Tên tổ chức". “GeekforGeek”, “logo”. { "@kiểu". “ImageObject”, “url”. “https. //phương tiện truyền thông. chuyên viên máy tính. org/wp-content/cdn-uploads/gfg_200x200-min. png” } }, “datePublished”. “2022-07-18”, “dateModified”. “2022-07-21” }

Công dụng của hàm tạo list() trong Python là gì?

Hàm tạo list() trả về một danh sách . Nếu iterable được truyền dưới dạng tham số, nó sẽ tạo một danh sách bao gồm các mục của iterable.

Chức năng danh sách trong Python với ví dụ là gì?

Hàm danh sách Python

Bộ () trong Python là gì?

Trăn. phương thức set() . cú pháp. đặt (có thể lặp lại) Tham số. Bất kỳ chuỗi có thể lặp lại nào như danh sách, bộ dữ liệu hoặc từ điển. trả lại. Tập rỗng nếu không có phần tử nào được truyền. used to convert any of the iterable to sequence of iterable elements with distinct elements, commonly called Set. Syntax : set(iterable) Parameters : Any iterable sequence like list, tuple or dictionary. Returns : An empty set if no element is passed.

Việc sử dụng phương pháp liệt kê là gì?

Được sử dụng để nối và thêm các phần tử vào cuối Danh sách . Phương pháp này được sử dụng để xóa tất cả các mục khỏi danh sách. Trả về chỉ số thấp nhất nơi phần tử xuất hiện.