How to Print a String Without ‘\n’ in Python

Strings, Printing and ‘\n’ The printing of a basic string is probably the first program the majority of people, myself included, write in Python –  does print(‘hello world’) sound familiar? From the outset we know the principle is simple, we can pass our string through the print() function and the output will be displayed in … Read more

101+ Free Python Books

Free Python Book

Books remain great learning devices — even in the age of AI. But why spending money when you can get them for free? This article compiles a list of 101++ FREE Python books to destroy any excuse of not learning Python. Everyone can afford to read free books! Also check out my two other free … Read more

Python Set clear()

Python’s set.clear() method removes all elements from this set. All variables that refer to this set object will refer to an empty set after calling the method. Here’s a minimal example where you remove three elements from a set at once by means of the s.clear() method: Syntax Let’s “dive” into the formal syntax of … Read more

Python Set copy()

Python’s set.copy() method creates and returns a flat copy of this set. Here’s a minimal example where you copy a set with two integers and a string value: Syntax Let’s dive into the formal syntax of the set.copy() method. set.copy() Argument Data Type Explanation – – – The set.copy() method doesn’t take any argument. If … Read more

Python Set difference()

Python’s set.difference(sets) method creates and returns a new set containing all elements of this set, except the ones in the given set argument or arguments. The resulting set has at most as many elements as this set. Here’s a minimal example where we return a new set with the elements from an existing set after … Read more

Python Set difference_update()

Python’s set.difference_update(*args) method removes all elements from this set that are members of any of the given set arguments. For example, s.difference_update({1, 2}) removes elements 1 and 2 from the set s. Its return value is None because it modifies the set it is called upon rather than creating a new set. Here’s a minimal … Read more

Python Set discard()

Python’s set.discard(x) method removes an element x from this set if it is a member. Otherwise does nothing. Here’s a minimal example where you remove the string element ‘Bob’ from the set by means of the s.discard() method: Syntax Let’s “dive” into the formal syntax of the set.discard() method. set.discard(element) Argument Data Type Explanation element … Read more

Python Set intersection()

Python’s set.intersection(sets) creates and returns a new set consisting of the elements that are members of all sets — this and the set argument(s). The resulting set has at most as many elements as any other set given in the argument list. Here’s a minimal example that creates a new set arising from the intersection … Read more

Python Set intersection_update()

Python’s set.intersection_update(sets) removes each element that’s not a member of all arguments sets. Here’s a minimal example that modifies existing set object s to be the intersection between sets s and t: Syntax Let’s dive into the formal syntax of the set.intersection_update() method. set.intersection_update(*sets) Argument Data Type Explanation *sets One or more sets The elements … Read more

Python Set isdisjoint()

Python’s set.isdisjoint(set) returns True if no element from this set is a member of the specified set. Sets are disjoint if and only if their intersection is the empty set. Here’s a minimal example that checks whether sets s and t are disjoint: Syntax Let’s dive into the formal syntax of the set.isdisjoint() method. set.isdisjoint(set) … Read more

Python Set issubset()

Python’s set.issubset(set) returns True if all elements of this set are members of the specified set argument. It determines whether the set on which the method is called is the subset of the specified set. Here’s a minimal example that checks whether sets s is a subset of t: Another minimal Harry Potter example: Syntax … Read more