Python List

WBOY
Release: 2024-08-06 20:15:52
Original
1322 people have browsed it

Python List

Empty List

In python it means that a list which is empty.

packages=[]
''
Copy after login

List

List means there are many things which are there in the list.
eg:
list
123
235
574
665

List in Python

eg:

packages=["fruits","vegetables","notebooks"]
Copy after login

Accessing Single List

eg:

packages=["fruits","vegetables","notebooks"]
item=packages[1]

'fruits'
Copy after login

Append() Method

eg:

packages=["fruits","vegetables","notebooks"]
packages.append("pencils")

packages=["fruits","vegetables","notebooks","pencils"]
Copy after login

Remove() method

eg:

packages=["fruits","vegetables","notebooks","pencils"]
packages.remove("fruits")

packages=["vegetables","notebooks","pencils"]
Copy after login

Pop() Method

eg:

packages=["vegetables","notebooks","pencils"]
last_package=packages.pop

packages=["vegetables","notebooks"]
Copy after login

Finding Position by using Index() Method

eg:

packages=["vegetables","notebooks"]
position=packages.index("vegetables")

'1'
Copy after login

Sort() Method

It used to use the list in alphabetical order.
eg:

packages=["fruits","vegetables","notebooks","pencils"]
packages.sort()

["fruits","notebooks","pencils","vegetables"]
Copy after login

This things and all I learn in my class.
Thank You.
S. Kavin

The above is the detailed content of Python List. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!