Category: Tutorials
-
Access Tuple Items
Access Tuple Items The most common way to access values within a Python tuple is using indexing, We just need to specify the index of the elements we want to retrieve to the square bracket [] notation. In Python, a tuple is an immutable ordered collection of elements. “Immutable” means that once a tuple is created, we cannot modify…
-
Tuples
Tuple is one of the built-in data types in Python. A Python tuple is a sequence of comma separated items, enclosed in parentheses (). The items in a Python tuple need not be of same data type. Following are some examples of Python tuples − The empty tuple is written as two parentheses containing nothing…
-
List Exercises
Python List Exercise 1 Python program to find unique numbers in a given list. Open Compiler It will produce the following output − Python List Exercise 2 Python program to find sum of all numbers in a list. Open Compiler It will produce the following output − Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a…
-
List Methods
List is one of the fundamental data structures in Python, It provides a flexible way to store and manage a collection of items. It has several built-in methods that allow you to add, update, and delete items efficiently. Lists in Python can contain items of different data types, including other lists, making them highly flexible…
-
Join Lists
Join Lists in Python Joining lists in Python refers to combining the elements of multiple lists into a single list. This can be achieved using various methods, such as concatenation, list comprehension, or using built-in functions like extend() or + operator. Joining lists does not modify the original lists but creates a new list containing the combined elements.…
-
Copy Lists
Copying a List in Python Copying a list in Python refers to creating a new list that contains the same elements as the original list. There are different methods for copying a list, including, using slice notation, the list() function, and using the copy() method. Each method behaves differently in terms of whether it creates…
-
Sort Lists
Sorting Lists in Python Sorting a list in Python is a way to arrange the elements of the list in either ascending or descending order based on a defined criterion, such as numerical or lexicographical order. This can be achieved using the built-in sorted() function or by calling the sort() method on the list itself,…
-
List Comprehension
List Comprehension in Python A list comprehension is a concise way to create lists. It is similar to set builder notation in mathematics. It is used to define a list based on an existing iterable object, such as a list, tuple, or string, and apply an expression to each element in the iterable. Syntax of Python List Comprehension The…
-
Loop Lists
Loop Through List Items Looping through list items in Python refers to iterating over each element within a list. We do so to perform the desired operations on each item. These operations include list modification, conditional operations, string manipulation, data analysis, etc. Python provides various methods for looping through list items, with the most common being the for…
-
Remove List Items
Removing List Items Removing list items in Python implies deleting elements from an existing list. Lists are ordered collections of items, and sometimes you need to remove certain elements from them based on specific criteria or indices. When we remove list items, we are reducing the size of the list or eliminating specific elements. We…