Articles on Trending Technologies

Technical articles with clear explanations and examples

How to wrap long lines in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 23K+ Views

In Python, we will come across situations where we encounter long lines of code that exceed the recommended line length of 79 characters (suggested by the Python style guide). To improve code readability, Python provides several ways to wrap long lines. In this article, we will explore the various methods to wrap long lines in Python. Using Backslash(\) The Backslash(\) is used as the line continuation character in Python. It indicates the compiler that the statement continues on the next line. If we try to place anything (word, space or comment) after the backslash, it will result in ...

Read More

How can I test if a string starts with a capital letter using Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 16K+ Views

A string is a collection of characters that can represent a single word or a whole sentence. Unlike Java, there is no need to declare Python strings explicitly; we can directly assign a string value to a literal. While working with the string, we will encounter situations to check whether the string starts with a capital letter. This can be useful for validating the names or sentences to ensure they follow certain formatting rules. Python provides multiple methods to test this condition. In this article, we will explore how to test if a string with a capital letter. ...

Read More

How to concatenate a string with numbers in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 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

How to remove characters except digits from string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 11K+ Views

While working with the texts in Python, we will find the strings that contain a mix of characters such as letters, digits, and white-space. In some scenarios, we may need to extract only the numeric digits from such strings. For achieving this, Python provides various ways. Let's explore one by one - Using Python str.isdigit() Method The first approach is by using the Python isdigit() method. It is used to check whether the character is a digit. It returns true if all the characters in the input string are digits. Syntax Following is the syntax for Python str.isdigit() ...

Read More

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

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 32K+ Views

In this article, we are going to find out how to check if the type of a variable is a string in Python. It is necessary to verify the type of a variable before performing the operations. For example, if we want to ensure that the variable is a string before using the string methods like upper(),  lower(). If the variable is not of the expected type, calling these methods will raise an error. Python provides various ways to check if the variable is of type string. Let's dive into the article to learn more about it. ...

Read More

How to extract a substring from inside a string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 5K+ Views

In programming, a substring is a smaller part of the string. Extracting the substring is a task in Python, whether we are analysing the user input or manipulating URLs, we will find ourself to grab a portion of the string. For achieving, Python provides the various way, Let's dive into the article to learn more about extracting the substring from the string. Using Python slicing The first approach is by using the Python slicing, It is the most common way to extract the substrings. Simply, we require the start and end indices. Example In the following example, ...

Read More

How to find the nth occurrence of substring in a string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 5K+ Views

While working with the strings, the common requirement is searching for a specific substring within a larger string. Python provides built-in methods that allow you to locate the first occurrence of a substring. But what if the substring appears multiple times. For example, consider the string "Welcome to the Tutorialspoint to". If we look for the second occurrence of the substring "to", using the find() will get only the first match, but we need an approach that searches beyond the first occurrence, counting each one until the nth. In this article, we will explore how to find the nth ...

Read More

How do I split a multi-line string into multiple lines?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 7K+ Views

A string is a collection of characters that may be used to represent a single word or an entire phrase. Strings are useful in Python since they don't need to be declared explicitly and may be defined with or without a specifier. In this article, we are going to find out how to split a multi-line string into multiple lines in Python. While working with the strings in programs, we will come across multi-line strings. To process such strings one by one, we need to split the string into individual lines. In this article, we will explore different methods. ...

Read More

How to convert a string to a list of words in python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 10K+ Views

Strings are one of the most commonly used data types. In this article, we are going to find out how to convert a string to a list of words in Python. Converting the string into a list is helpful when dealing with user inputs or when we want to manipulate individual words in a string. Python provides several ways to achieve this. Let's explore them one by one. Using Python str.split() Method Python str.split() method accepts a separator as a parameter, splits the string at the specified separator, and returns the result as a list. If we use the split() ...

Read More

How to sort the letters in a string alphabetically in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 7K+ Views

In Python, Sorting the string alphabetically is a common task helps for string manipulation or text analysis. It is used in creating the anagrams, checking for permutations, or standardizing the input for consistent processing, for example, turning 'banana' into 'aaabnn'. In this article, we will explore how to sort the letters in a string alphabetically, this can be done by using the Python built-in function. Using Python sorted() Function The Python sorted() function is used to return a new sorted list from the items in the iterable object. The order of sorting can be set to either ascending ...

Read More
Showing 861–870 of 61,248 articles
« Prev 1 85 86 87 88 89 6125 Next »
Advertisements