Category: Tutorials

  • Remove Set Items

    Remove Set Items Removing set items implies deleting elements from a set. In Python, sets are mutable, unordered collections of unique elements, and there are several methods available to remove items from a set based on different criteria. We can remove set items in Python using various methods such as remove(), discard(), pop(), clear(), and set comprehension.…

  • Add Set Items

    Add Set Items Adding set items implies including new elements into an existing set. In Python, sets are mutable, which means you can modify them after they have been created. While the elements within a set must be immutable (such as integers, strings, or tuples), the set itself can be modified. You can add items to a…

  • Access Set Items

    Access Set Items The primary way to access set items is by traversing the set using a loop, such as a for loop. By iterating over the set, you can access each element one by one and perform operations on them as needed. In Python, sets are unordered collections of unique elements, and unlike sequences (such as lists or tuples), sets do…

  • Sets

    Sets in Python In Python, a set is an unordered collection of unique elements. Unlike lists or tuples, sets do not allow duplicate values i.e. each element in a set must be unique. Sets are mutable, meaning you can add or remove items after a set has been created. Sets are defined using curly braces {} or…

  • Python Tuple Exercises

    Python Tuple Exercise 1 Python program to find unique numbers in a given tuple − Open Compiler It will produce the following output − Python Tuple Exercise 2 Python program to find sum of all numbers in a tuple − Open Compiler It will produce the following output − Learn Python in-depth with real-world projects through our Python certification course. Enroll and…

  • Tuple Methods

    Tuple is one of the fundamental data structures in Python, and it is an immutable sequences. Unlike lists, tuples cannot be modified after creation, making them ideal for representing fixed collections of data. This immutability play a crucial role in various scenarios where data stability and security are important. It can contain elements of different…

  • Join Tuples

    Joining Tuples in Python Joining tuples in Python refers to combining the elements of multiple tuples into a single tuple. This can be achieved using various methods, such as concatenation, list comprehension, or using built-in functions like extend() or sum(). Joining tuples does not modify the original tuples but creates a new tuple containing the combined elements. Joining…

  • Loop Tuples

    Loop Through Tuple Items Looping through tuple items in Python refers to iterating over each element in a tuple sequentially. In Python we can loop through the items of a tuple in various ways, with the most common being the for loop. We can also use the while loop to iterate through tuple items, although it requires additional handling of the loop…

  • Unpack Tuple Items

    Unpack Tuple Items The term “unpacking” refers to the process of parsing tuple items in individual variables. In Python, the parentheses are the default delimiters for a literal representation of sequence object. Following statements to declare a tuple are identical. Example To store tuple items in individual variables, use multiple variables on the left of assignment operator, as…

  •  Update Tuples

    Updating Tuples in Python In Python, tuple is an immutable sequence, meaning once a tuple is created, its elements cannot be changed, added, or removed. To update a tuple in Python, you can combine various operations to create a new tuple. For instance, you can concatenate tuples, slice them, or use tuple unpacking to achieve the desired…