Programming Articles

Page 653 of 2547

How does the del operator work on a tuple in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 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 cannot be modified, whereas lists can, and they use parentheses instead of square brackets. Though we cannot change individual elements of a tuple, the del operator works with them. In this article, we are going to discuss how the del operator works on tuples in Python. 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 ...

Read More

How does the repetition operator work on a tuple in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 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, ...

Read More

How does concatenation operator work on tuple in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 2K+ Views

The concatenation operator (+) is 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, while keeping the original tuples unchanged. In this article, we will discuss how the concatenation operator works on tuples in Python with practical examples. 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 since tuples are immutable in Python. The concatenation operator (+) merges ...

Read More

How does the \'in\' operator work on a tuple in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 4K+ 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 ...

Read More

What is the difference between a python tuple and a dictionary?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 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 ...

Read More

How to declare a variable in Python without assigning a value to it?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 12K+ Views

Python variables are names that refer to objects in memory. Normally, you assign a value when creating a variable, but sometimes you need to declare a variable without an initial value. Python provides several approaches to accomplish this. For example, a = 100 creates a variable a pointing to an integer object with value 100. But what if you want to declare a without assigning a specific value? Using the None Keyword The most common approach is using None, Python's built-in null value. None is a special object of type NoneType that represents the absence of a ...

Read More

What is the difference between working of append and + operator in a list in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 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 modifying the original list in place. The '+' operator is used to create a new list by concatenating existing lists. Behaviour of "+" Operator with Python Lists Python uses the '+' operator to create a new list by combining existing lists. When the '+' symbol is used, a new list is created with all elements from both ...

Read More

What is a sequence data type in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 18K+ Views

Sequence data types in Python are ordered collections that allow you to store and access multiple items using indexing. The three main sequence data types are lists, strings, and tuples. Each has distinct characteristics regarding mutability and the type of data they can store. Lists are mutable and can hold data of any type, strings are immutable and store only text characters, while tuples are immutable but can store any type of data. Understanding these differences is crucial for choosing the right data structure for your needs. List Lists are the most flexible sequence type in Python. ...

Read More

How to index and slice lists in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 5K+ Views

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. In Python, a list is like a box in which you can keep many things like numbers, names, or your favorite fruits. Let us say you have a list like this ? fruits = ["apple", "banana", "mango"] print(fruits) ['apple', 'banana', 'mango'] Here, each fruit has a position in the list. But in Python, we start counting from 0, not 1. So ...

Read More

How does repetition operator work on list in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 4K+ Views

In Python, the * symbol serves as the repetition operator when used with lists. Instead of multiplication, it creates multiple copies of a list and concatenates them together into a single new list. Basic Syntax The repetition operator follows this pattern ? # Syntax: list * number new_list = original_list * repetition_count Single Element Repetition Create a list with repeated single elements ? numbers = [0] * 5 print(numbers) [0, 0, 0, 0, 0] The list [0] contains one element. The repetition operator makes 5 copies ...

Read More
Showing 6521–6530 of 25,466 articles
« Prev 1 651 652 653 654 655 2547 Next »
Advertisements