
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

9K+ Views
In Python, the backslash-escaped string contains the characters that are followed by backslash(\), which are used as escape characters. For example, represents the literal characters "" and "n" (not a new line). In some scenarios, we need to unescape such a string, i.e, convert these sequences back to their intended special characters or read them as normal text. Python provides several ways to achieve this. In this article, we will explore how to un-escape a backslash-escaped string. Using Python .decode() Method The Python decode() method is used to decode the string using the codec ... Read More

8K+ Views
Concatenation is nothing but the process of joining two or more strings together. In Python, if one value is a number (integer or float), we can't directly concatenate it with a string using the '+' operator, as it raises a TypeError. Python does not allow the implicit conversion between strings and numbers during the concatenation. So, we need to explicitly convert the numbers to a string. Using Python str() Function The Python str() function is used to convert the given value into a string. In this approach, we are going to apply the str() function to ... Read More

6K+ Views
In Python formatting a floating point number to a fixed width can be done by using methods like Python's f-strings and the flexible format() method. Float formatting methods The two built-in float formatting methods are as follows f-strings: Convenient way to set decimal places, spacing and separators. str.format(): This method allows to formatting types inside the placeholders to control how the values are displayed. ... Read More

4K+ Views
In many programming languages, trying to access the element that is out of range of a string or list results in the IndexError. But Python behaves differently when it comes to substring slicing. Instead of generating the error, Python handles the out-of-range in slicing operations by adjusting the indices to fit the valid limits. This makes the Python slicing safe and appropriate. Let's dive into the article to understand how slicing with out-of-range indices works in Python with examples. Python slice() Function The Python slice() function is used to return the slice object that can be used ... Read More

3K+ Views
The escape sequences are the special characters that are used to represent the whitespace characters, quotes, backslashes or non-printable characters within the string. These sequences start with the backslash followed by the character, For example result in newline. However, in some cases we will come across the situations to process or even to ignore these situations. In this article we will learn how to process the escape sequences. Example Let's look at the following example, where we are going to consider the basic approach to process the escape sequences. str1 = "Hello\tEveryoneWelcome to TutorialsPoint" print(str1) ... Read More

9K+ Views
The Lists in Python are used to store collections of items such as numbers, strings. While working with the list of strings, it is common to find a empty strings in the list. An empty string is nothing but a string value with zero length. Officially they are present as elements in the list, but does not hold any data and interfere in the operations like sorting, filtering. So, removing the empty strings is essential to ensure the list contains only valid values. For achieving this, Python provides the several ways. Let's dive into the article to learn ... Read More

4K+ Views
The strings are the fundamental data types that are used to store text. When working with the string, Checking if the string is empty or not is a common task. An empty string is nothing but the string with zero characters. There are various to check if a sting is empty, But choosing the elegant ways helps to improve the code readability. Let's dive into the article to learn more about it. Using if not my_string In Python, empty strings are considered as falsy, Which evaluates to false in a boolean content. So using not my_string returns true ... Read More

332 Views
In Python, strings and bytes are two different types of data, Where the strings are the sequences of unicode characters used for text representation, While bytes are sequences of bytes used for binary data. Converting strings to bytes is used when we want to work with the raw binary data or perform low-level operations. This can be done by using the built-in encode method. Using Python encode() Method The Python encode() Method is used to convert the string into bytes object using the specified encoding format. Syntax Following is the syntax for Python encode() method ... Read More

10K+ Views
While working with the strings, Checking if the string exists inside another string is a common task and can be achieved by using the in keyword. But, In this article we are going to see how to check if multiple strings exist in another string in Python. For example, checking the multiple strings: "TP", "WELCOME", exists in the string "WELCOME to TP". For achieving this, Python provides different methods including loops, any() and all(). Using Python any() Function The Python any() function returns true if any of the element of the given iterable (such as list, ... Read More

11K+ 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 Python, it is possible to span strings across many lines. It can also be applied to lengthy code comments. Triple quotes can also contain special characters like TAB, verbatim, or NEWLINES. As the name would imply, the syntax consists of three single or double quotes placed consecutively. Example In the ... Read More