Course
Lists
Python Tutorial
This Python tutorial has been written for the beginners to help them understand the basic to advanced concepts of Python Programming Language. After completing this tutorial, you will find yourself at a great level of expertise in Python, from where you can take yourself to the next levels to become a world class Software Engineer.
Lists
List is one of the built-in data types in Python. A Python list is a sequence of comma separated items, enclosed in square brackets
[ ]
. The items in a Python list need not be of the same data type.Following are some examples of Python lists
list1 = ["Rohan", "Physics", 21, 69.75]list2 = [1, 2, 3, 4, 5]list3 = ["a", "b", "c", "d"]list4 = [25.50, True, -55, 1+2j]
In Python, a list is a sequence data type. It is an ordered collection of items. Each item in a list has a unique position index, starting from 0.
A list in Python is similar to an array in C, C++ or Java. However, the major difference is that in C/C++/Java, the array elements must be of same type. On the other hand, Python lists may have objects of different data types.
A Python list is mutable. Any item from the list can be accessed using its index, and can be modified. One or more objects from the list can be removed or added. A list may have same item at more than one index positions.
Python List Operations
In Python, List is a sequence. Hence, we can concatenate two lists with "
+
" operator and concatenate multiple copies of a list with "*
" operator. The membership operators "in" and "not in" work with list object.Practice with Online Editor
Note: This Python online Editor is a Python interpreter written in Rust, RustPython may not fully support all Python standard libraries and third-party libraries yet.
Remember to save code(Ctrl
+S
Or
Command
+S
) before run it.