Category: Strings
How to create multi line string objects in python ?
In this article we will discuss different ways to create long multi line string in python. Using triple quotes to create string of multiple lines We can wrap the multi line string in triple quotes i.e. either <> and assign it to a string variable. It will be stored in same multi line format. Checkout …
How to create multi line string objects in python ?Read More
Count occurrences of a single or multiple characters in string and find their index positions
In this article we will discuss different ways to count occurrences of a single character or some selected characters in a string and find their index positions in the string. Count Occurrences of a single character in a String using string.count() In Python the String class contains a method to count to the occurrences of …
Python: How to get first N characters in a string?
In this article, we will discuss how to fetch/access the first N characters of a string in python. This N can be 1 or 3 etc. Table Of Contents Get the first character of a string in python Get first N characters in a string Get first three characters of a string in python Get …
Python: How to get Last N characters in a string?
In this article, we will discuss how to fetch the last N characters of a string in python. This N can be 1 or 4 etc. In python, a String is a sequence of characters, and each character in it has an index number associated with it. For example, we have a string variable sample_str …
Check the first or last character of a string in python
In this article, we will discuss different ways to check the content of the first or last character of a string in python. Indexing in String Every character in a string has an index number associated with it. This index can be a positive or negative number. For example, we have a string, Advertisements sample_str …
Check the first or last character of a string in pythonRead More
Check if type of a variable is string in Python (3 Ways)
In this article we will discuss three different ways to check if the type of a variable is string or not in python. Check if type of a variable is string in python using isinstance() function Python provides a function to check the type of a variable i.e. Advertisements isinstance(object, classinfo) This function returns True …
Check if type of a variable is string in Python (3 Ways)Read More
Python: Capitalize the first letter of each word in a string?
In this article we will discuss 5 different ways to convert first letter of each word in a string to uppercase. We will also discuss what are the limitations of each approach and which one is best for us. Use title() to capitalize the first letter of each word in a string in python Python …
Python: Capitalize the first letter of each word in a string?Read More
Python: How to convert integer to string (5 Ways)
In this article we will discuss 5 different ways to convert a integer to string in python. Using str() to convert an int to string in python Python provides a function str(object). It accepts an object as an argument and returns a string representation of that object. So, if we pass the an integer as …
Python: Check if string is empty or blank or contain spaces only
In this article we will discuss different ways to check if a given string is either empty or contains only spaces. Check if a string is empty using len() len() function in python accepts a sequence as an argument and returns the number of elements in that sequence. So, if we pass a string as …
Python: Check if string is empty or blank or contain spaces onlyRead More
Python: Check if any string is empty in a list?
In this article we will discuss different ways to check if a list contains any empty or blank string in python. Use any() and List Comprehension to check if list contains any empty string We have created a function to check if a string is empty. It will also consider a string empty if it …