Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Articles - Page 994 of 1048
27K+ Views
List and Tuple in Python are classes of data structures. The list is dynamic, whereas the tuple has static characteristics. In this article, we will convert a list into a tuple by using a few methods. Each of these methods is discussed below. Converting List into Tuple using tuple() We can convert a list into a tuple using the tuple() function. This function accepts a list as a parameter, converts into a tuple and returns the result.Example 1 In the following program, we convert a list to a tuple using the tuple() function. # using tuple() built-in function list_names=['Meredith', 'Kristen', 'Wright', ... Read More
6K+ Views
A tuple is an ordered and immutable collection of Python objects separated by commas. Like lists, tuples are sequences. Tuples differ from lists in that they can not be modified, whereas lists can, and they use parentheses instead of square brackets. Though we can not change individual elements of a tuple, the del operator works with them. In this article, we are going to discuss the use of the del operator on a tuple. The del Operator with Tuples The del operator in Python is used to delete variables from the current scope. When you use "del" on a tuple ... Read More
6K+ Views
In Python, the "*" operator can be used to repeat a tuple multiple times. This is known as tuple repetition. It creates a new tuple with repeated elements but does not modify the original tuple. Following are some points to remember - The repetition operator (*) creates a new tuple. Individual items are not repeated, only the entire tuple. The repeat count must be a non-negative integer. The original tuple is unaltered. Accepts tuples of any length and mixed data types. How Repetition Operator Works? When you apply '*' to a tuple with an integer, Python duplicates the ... Read More
2K+ Views
The concatenation operator (+) is basically used to join two or more tuples together in Python. This operation returns a new tuple that contains all the items of the original tuples. In this article, we will discuss how the concatenation operator works on tuples in Python. But first, let us see how concatenation works. How Concatenation Works? When you use the concatenation operator on tuples, Python creates a new tuple that includes all the elements from the tuples being concatenated. The original tuples remain unchanged. As you may know, tuples in Python are immutable means their values cannot be changed ... Read More
3K+ Views
Python offers the 'in' operator to verify that a value is present in a tuple. This operator is very useful when you are looking for items in a collection without requiring loops or complex logic. In this article, we will discuss the 'in' operator and how it works on tuples in Python. Before moving on, we will first discuss tuples. Tuples in Python are an immutable sequence, and they are created by placing a sequence of values separated by a 'comma', with or without the use of parentheses for data grouping. Tuples can have any number of elements and any ... Read More
5K+ Views
Tuples in Python are immutable, which means once we create them, we can not change their items. In this article, we will discuss why tuples are immutable before moving on, and we will understand tuples in detail. Tuples in Python Tuples are a data type that belongs to the sequence data type category. They are similar to lists in Python, but they have the property of being immutable. We can't change the elements of a tuple, but we can perform operations suchas counting the number of elements, accessing elements using an index, retrieving the type of the elements, etc. Tuples ... Read More
19K+ Views
Python offers many built-in data structures like lists, tuples, sets, and dictionaries, which are used to store and manage data easily. In this article, we will discuss the difference between a Python tuple and a dictionary. Tuple Tuples are a data type that belongs to the sequence data type category. They are similar to lists in Python, but they are immutable. We can't change the elements of a tuple, but we can execute a variety of actions on them, such as count, index, type, etc. Tuples are created in Python by placing a sequence of values separated by a 'comma', with or ... Read More
3K+ Views
In this article we are going to discuss about the difference between Python list and array. As you may know both of these are ways to store a collection of items like a bunch of numbers or words but they are not exactly the same. So understanding how they are different will help you select the right one when you are writing your program. List Lists are one of the four most commonly used data structures provided by Python. A list is a data structure in python that is mutable and has an ordered sequence of elements. Lists also support ... Read More
11K+ Views
Python variable is a name that you give to something in your program. It basically helps you keep track of objects, which are things like numbers, words or any other data. When you assign an object to a variable, you can use that name to refer to that object later. The data, on the other hand, is still contained within the object. For example, a is assigned the value 100. Here 'a' is a variable. a = 100 This assignment creates an integer object with the value 100 and assigns the variable a to point to that object. In ... Read More
4K+ Views
In this article, we will see the differences between two common ways of adding elements to lists in Python: the append method and the "+" operator. The append() method is used to add elements to the list by utilizing a mutator() method. The '+' operator is used to create a new list with the capacity for one more element. Behaviour of "+" with Python Lists Python accesses each element of the first list by using the '+' operator. When the '+' symbol is used, a new list with the capacity for one more element is produced. The old ... Read More