Pythonic

Pythonic

3 Articles Published

Articles by Pythonic

3 articles

What is "not in" operator in Python?

Pythonic
Pythonic
Updated on 24-Mar-2026 5K+ Views

In Python, the not in membership operator evaluates to True if it does not find a variable in the specified sequence and False otherwise. Syntax element not in sequence Example with Lists Let's check if elements are not present in a list ? a = 10 b = 4 numbers = [1, 2, 3, 4, 5] print(a not in numbers) print(b not in numbers) True False Since a (10) doesn't belong to numbers, a not in numbers returns True. However, b (4) can be found in ...

Read More

How to pop-up the first element from a Python tuple?

Pythonic
Pythonic
Updated on 24-Mar-2026 4K+ Views

Python tuples are immutable, meaning you cannot directly remove elements from them. However, you can achieve the effect of "popping" the first element by converting the tuple to a list, removing the element, and converting back to a tuple. Method 1: Using list() and pop() Convert the tuple to a list, use pop(0) to remove the first element, then convert back to a tuple ? # Original tuple T1 = (1, 2, 3, 4) print("Original tuple:", T1) # Convert to list, pop first element, convert back L1 = list(T1) first_element = L1.pop(0) T1 = tuple(L1) ...

Read More

What is the difference between __str__ and __repr__ in Python?

Pythonic
Pythonic
Updated on 24-Mar-2026 320 Views

The __str__ and __repr__ methods in Python serve different purposes for string representation of objects. The __str__ method provides a human-readable representation, while __repr__ provides an unambiguous, developer-friendly representation that ideally can recreate the object. Key Differences The built-in functions str() and repr() call the __str__() and __repr__() methods respectively. The repr() function computes the official representation of an object, while str() returns the informal representation. Method Purpose Target Audience Should be Evaluable? __str__ Human-readable End users No __repr__ Unambiguous Developers Ideally yes Example with Integer Objects ...

Read More
Showing 1–3 of 3 articles
« Prev 1 Next »
Advertisements