Tarun Chandra has Published 61 Articles

How to check if type of a variable is string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 08:55:25

25K+ Views

In this article, we are going to find out how to check if the type of a variable is a string in Python. The first approach is by using the isinstance() method. This method takes 2 parameters, the first parameter being the string that we want to test and the ... Read More

How to remove characters except digits from string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 08:52:54

7K+ Views

In this article, we are going to find out how to remove characters except digits from a string in Python The first approach is by using the if statement in a for loop and joining them using join() method. We will iterate the string using the for loop and then ... Read More

How to split string on whitespace in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 08:28:42

13K+ Views

In this article, we are going to find out how to split a string on whitespace in Python. The first approach is by using the inbuilt method split(). This method splits the given string at our desired delimiter. The split() method accepts a parameter named as a delimiter, it specifies ... Read More

How to concatenate a string with numbers in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 08:26:33

5K+ Views

In this article, we are going to find out how to concatenate a string with numbers in Python. The first approach is by typecasting the number into a string using typecasting. After typecasting the number, we can concatenate using the ‘+’ operator. Type casting or type conversion in Python are ... Read More

How to format a floating number to fixed width in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 08:20:58

4K+ Views

Floating numbers are the numbers which include a decimal point and in other words are also called as real numbers. By default, the number of decimal points in floating number is 6 but we can modify that using the methods given below. In this article, we are going to find ... Read More

How to remove empty strings from a list of strings in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 08:00:42

4K+ Views

In this article, we are going to find out how to remove empty strings from a list of strings in Python.. The first approach is by using the inbuilt method filter(). This method takes input from a list of strings and removes empty strings and returns the updated list. It ... Read More

How to check if multiple strings exist in another string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 07:58:38

5K+ Views

In this article, we are going to see how to check if multiple strings exist in another string in Python. Imagine a scenario where we must satisfy 50 requirements in order to work. To determine whether conditions are true, we typically employ conditional statements (if, if−else, elif, nested if). However, ... Read More

How to create a long multi-line string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 07:53:11

9K+ Views

In this article, we are going to focus on how to create a long multi−line string in Python. The first approach is by using triple quotes, we should add a triple quote then we can add separate line inside the quotes, the multi-line string is created. Using triple quotes in ... Read More

How do I execute a string containing Python code in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 07:49:43

15K+ Views

In this article, we are going to find out how to execute a string containing Python code in Python. To execute a string containing Python code we should take the input string as multi-line input using triple quotes, then we will use the inbuilt function exec(). This will take a ... Read More

How to get a function name as a string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 07:46:38

14K+ Views

In this article, we are going to find out how to get a function name as a string in Python. The first approach is by using the function property __name__. This property will return the name of the function when the property is called. This is only present in Python ... Read More

Advertisements