Why do we use join() function in Python?

The join() is defined as a string method which returns a string value. It is concatenated with the elements of an iterable. It provides a flexible way to concatenate the strings. See an example below. str = “Rohan” str2 = “ab” # Calling function str2 = str.join(str2) # Displaying result print(str2) Output: aRohanb In Python, … Read more

How to remove whitespaces from a string in Python?

To remove the whitespaces and trailing spaces from the string, Python providies strip([str]) built-in function. This function returns a copy of the string after removing whitespaces if present. Otherwise returns original string. string = ” javatpoint “ string2 = ” javatpoint “ string3 = ” javatpoint” print(string) print(string2) print(string3) print(“After stripping all have placed in … Read more

What is swapcase() function in the Python?

It is a string’s function which converts all uppercase characters into lowercase and vice versa. It is used to alter the existing case of the string. This method creates a copy of the string which contains all the characters in the swap case. If the string is in lowercase, it generates a small case string … Read more

How to overload constructors or methods in Python?

Python’s constructor: _init__ () is the first method of a class. Whenever we try to instantiate an object __init__() is automatically invoked by python to initialize members of an object. We can’t overload constructors or methods in Python. It shows an error if we try to overload. class student: def __init__(self,name): self.name = name def … Read more

What is the difference between remove() function and del statement?

You can use the remove() function to delete a specific object in the list. If you want to delete an object at a specific location (index) in the list, you can either use del or pop. Note: You don’t need to import any extra module to use these functions for removing an element from the … Read more