Python Articles

Page 167 of 855

Python Program to Replace Elements in a Tuple

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 5K+ Views

In this article, you will learn how to replace elements in a tuple using Python. Since tuples are immutable, we cannot directly modify their elements. Instead, we need to use specific techniques to create new tuples with updated values. Before exploring the replacement methods, let's understand what tuples are in Python. What is a Tuple in Python? A tuple is one of Python's four built-in data types for storing collections. The other three are list, set, and dictionary, each with unique features and applications. Tuples are ordered and immutable collections. We create tuples by placing elements ...

Read More

Python Program to search an element in a tuple

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 7K+ Views

In Python, searching for elements within a data structure is a common task and different types of data structures should aim to provide efficient methods for searching. The problem of searching involves finding a specific element within a container and returning a value indicating whether it was found or not. One data structure that can be used for this task is a tuple, which stores a collection of different types of data in a single variable. These items can be accessed by their index and Python offers various methods to work with them. Tuples are immutable, meaning that once ...

Read More

Python Program to check if the tuple is empty

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 4K+ Views

In Python, checking if a tuple is empty is a common operation needed to determine what actions to take in a program. A tuple is an ordered collection of items that is immutable, meaning its contents cannot be changed after creation. A tuple is considered empty if it contains zero elements. Python provides several methods to check for empty tuples, each with different advantages. What is a Tuple? A tuple in Python is defined using parentheses and can store heterogeneous data ? # Creating tuples non_empty_tuple = (1, 'a', 3.7) empty_tuple = () print("Non-empty ...

Read More

Python Program to add element to first and last position of linked list

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 581 Views

In Python, a linked list is a linear data structure that consists of a chain of nodes, where each node contains a value and a reference to the next node in the chain. In this article, we will be discussing how to add an element to the first and last position of a linked list in Python. Linked List in Python A linked list is a referential data structure that holds a group of elements. It is similar to an array but while data is stored in contiguous memory locations in an array, in a linked list ...

Read More

Python Program to remove duplicate elements from a dictionary

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 5K+ Views

In this article, we will discuss how to remove duplicate elements from a dictionary in Python. A dictionary stores key-value pairs where keys must be unique, but values can be duplicated. Sometimes we need to clean up data by keeping only unique values. We can declare a dictionary in the following way − sample_dict = {"brand": "Ford", "model": "Mustang", "year": 1964} print(sample_dict) {'brand': 'Ford', 'model': 'Mustang', 'year': 1964} A dictionary can contain duplicate values for different keys, but we might want to have only unique values. Let's explore two methods to remove ...

Read More

Python program to print the keys and values of the tuple

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 2K+ Views

In Python, tuples are a useful data type for storing a collection of items. Sometimes, it may be necessary to print the keys and values of a tuple in order to understand or debug your code. In this article, we will discuss how to print the keys and values of a tuple in Python. We will go over the syntax for accessing these elements and provide examples of how to do so. First, let's understand what tuples are and what we mean by keys and values in the context of tuples. What is a Python Tuple? ...

Read More

Python program to get first and last elements from a tuple

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 33K+ Views

Tuples are an important data type in Python that store multiple elements in a fixed order. In this article, we'll learn different methods to access the first and last elements from a tuple efficiently. What is a Tuple in Python? A tuple is an ordered collection of items that is immutable (unchangeable). Tuples are defined using round brackets and can store elements of different data types. Example fruits = ("apple", "banana", "cherry") print(fruits) print(type(fruits)) ('apple', 'banana', 'cherry') Method 1: Using Index Notation The most straightforward way to access ...

Read More

Python Program to compare elements in two dictionaries

Harshit Sachan
Harshit Sachan
Updated on 27-Mar-2026 3K+ Views

Dictionaries are a powerful data type in Python that allow you to store data as key-value pairs. In this article, we will discuss how to compare elements in two dictionaries using three different approaches: equality operator, loops, and list comprehension. Understanding Dictionaries In Python, a dictionary is created by placing key-value pairs within curly brackets { }, separated by commas. Values can be of any data type and can be duplicated, whereas keys must be unique and immutable. # Creating dictionaries dict1 = {"brand": "Ford", "model": "Mustang", "year": 1964} dict2 = {"brand": "Toyota", "model": "Camry", "year": ...

Read More

What's the fastest way to split a text file using Python?

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 38K+ Views

Splitting a text file in Python can be done in various ways, depending on the size of the file and the desired output format. In this article, we will discuss the fastest way to split a text file using Python, taking into consideration both performance and memory usage. Using split() Method One of the most straightforward ways to split a text file is by using the built-in split() function in Python. This function splits a string into a list of substrings based on a specified delimiter. For example, the following code splits a text file by newline ...

Read More

What is the Difference Between Scala and Python?

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 720 Views

Scala and Python are both powerful programming languages that are widely used for a variety of applications. They have some similarities, such as being high-level programming languages, but they also have some important differences. Whether you are a beginner or an experienced developer, this article will provide you with a comprehensive understanding of the key differences between Scala and Python and help you make an informed decision on which language to use for your next project. Detailed Comparison Factors Scala Python Syntax Scala is a statically typed language, which means that variables ...

Read More
Showing 1661–1670 of 8,549 articles
« Prev 1 165 166 167 168 169 855 Next »
Advertisements