Found 10784 Articles for Python

Python Program to sort a tuple of custom objects by properties

Harshit Sachan
Updated on 20-Feb-2023 17:51:14

335 Views

Let us now dive into what a custom object in python is. We know that python provides us with a lot of pre-defined datatypes which can be used to store various types of data. But there are times where we have to define custom datatypes that can store data that cannot be represented by built-in datatypes. For this purpose, python provides us “classes”, these classes help us customize and create that is fit for our needs. A class can have data and function to implement some behavior. An example of implementing a class in python is as follows − class ... Read More

Python Program to Replace Elements in a Tuple

Harshit Sachan
Updated on 20-Feb-2023 15:57:46

4K+ Views

In this article, you will find out how to use Python to find the first and last elements of a tuple in this tutorial. The quick response is that you can access the first and last elements of the tuple in Python using the index operator([]). The methods described here can be used to obtain your single tuple element. Before diving in to the solution let us understand tuple in python. What is tuple in Python? A tuple is one of Python's four built-in data types for storing data collections. The other three are list, set, and dictionary, each ... Read More

Python Program to print key value pairs in a dictionary

Harshit Sachan
Updated on 20-Feb-2023 15:56:41

4K+ Views

A dictionary in python is a data structure which stores a collection of key value pairs. Unlike other data structures a dictionary contains 2 value at a particular place. A dictionary is a collection which is ordered, mutable and does not allow duplicate elements. A dictionary can be created by placing a sequence of elements within curly { } brackets , separated by ‘comma’ ( , ) . Dictionary holds pairs of values, one being the key and the other corresponding pair element being its value. Values in a dictionary can be of any data type and ... Read More

Python Program to search an element in a tuple

Harshit Sachan
Updated on 20-Feb-2023 15:55:54

4K+ 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 if it is not found. 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 created, they cannot ... Read More

Python Program to find the largest element in a tuple

Harshit Sachan
Updated on 20-Feb-2023 15:54:55

794 Views

One of the most common problems in computer science is the problem of searching. To check whether a given element exists in a variable is important and sometimes the item we must search for, can be the maximum, minimum, most frequent etc. in this article we will see how we can find the largest element in a tuple. We know that tuple is a pre-defined datatype that stores heterogenous data. It is sort of a container that holds several items inside it. We can define a tuple in python using the round brackets enclosing the data that we ... Read More

Python Program to pass the tuple as function arguments

Harshit Sachan
Updated on 17-Feb-2023 14:34:03

5K+ Views

Tuples are an important data type in Python and are often used to store a fixed set of elements. In this article, we will be discussing how to pass a tuple as function arguments in Python. We will go over the syntax for passing tuple arguments and will provide examples of how to do so. Let us first understand the basics that, we will be needing to begin approaching the problem. The problem asks us to pass a tuple as a function argument, for that we need to know what a function in python is, what are function arguments, ... Read More

Python Program to Merge two Tuples

Harshit Sachan
Updated on 17-Feb-2023 14:29:44

3K+ Views

In Python, tuples are an immutable sequence type that is commonly used to store a collection of items. We can define a tuple in python using the round brackets enclosing the data that we wish to store − Var = (1, ‘a’, 3.7) There are times when we must use a single variable that has the elements of two or more different tuples. In those cases, we must know the ways we can merge them to create a single variable. In this article, we will be discussing how to merge two tuples in Python. Using + ... Read More

Python Program to check if the tuple is empty

Harshit Sachan
Updated on 17-Feb-2023 14:28:34

3K+ Views

In Python, it is often necessary to check if a tuple is empty in order to determine what actions to take in a program. A tuple in python is a pre-defined datatype that stores heterogeneous data, data of different types, in a single variable. The items can be indexed for further operations and python provides a wide array of methods to work upon them. They are immutable by nature which means we cannot make changes after we have created a tuple. This is whenever we perform some operation on the tuple a new tuple with resulting values is created. ... Read More

Python Program to add elements to a Tuple

Harshit Sachan
Updated on 17-Feb-2023 14:27:44

2K+ Views

In Python, tuples are immutable, meaning that once they are created, their elements cannot be modified. However, there may be times when you need to add elements to a tuple. In this article, we will be discussing how to add elements to a tuple in Python. We will go over the syntax for adding elements to a tuple and will provide examples of how to do so. Python tuples are very similar to Python lists, in that you can perform all the various operations that can be performed on lists. The only difference is that tuples cannot be modified after ... Read More

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

Harshit Sachan
Updated on 17-Feb-2023 15:26:42

353 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 in terms of an array but while the data is stored in contiguous memory location in an array, in linked ... Read More

Advertisements