Rajendra Dharmkar has Published 452 Articles

How to Convert Lowercase Letters in String to Uppercase in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 19:10:52

1K+ Views

In Python, a string is a sequence of characters. It's a type of data that represents text values, such as words, sentences, or even entire documents. Strings in Python are enclosed in either single quotes ('...') or double quotes ("..."), and can include alphanumeric characters, symbols, whitespace, and more. ... Read More

How to check if string or a substring of string ends with suffix in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 19:04:19

1K+ Views

To check if a string or a substring of a string ends with a suffix in Python, there are several ways to accomplish this. Here are some examples: Using the endswith() Method The endswith() method checks if the string ends with a specified suffix and returns a boolean value. To ... Read More

How to check if a substring is contained in another string in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 18:37:32

291 Views

A substring is a contiguous sequence of characters within a string. In other words, it's a smaller piece of text that appears within a larger piece of text. For example, in the string "lorem ipsum", the substring "lorem" appears within the larger string. Similarly, the substring "em i" appears within ... Read More

How to check if a string in Python is in ASCII?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 18:01:55

938 Views

ASCII stands for American Standard Code for Information Interchange. ASCII is a character encoding system that assigns a unique number to each letter, digit, and symbol on a standard keyboard. In Python, each character has a numerical value based on the ASCII code, which can be checked using the ord() ... Read More

How to check if a Python string contains only digits?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 17:46:01

9K+ Views

To check if a Python string contains only digits, we can use the built-in isdigit() method. This method returns True if all the characters in the string are digits, and False otherwise. Here's an example code snippet that demonstrates how to use isdigit(): To check if a string contains only ... Read More

How to check if a character in a string is a letter in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 17:33:08

8K+ Views

Here are three code examples that demonstrate how to check if a character in a string is a letter in Python: Using the isalpha() method The isalpha() method is a built-in method in Python that returns True if all the characters in a string are alphabets (letters) and False otherwise. ... Read More

How do I wrap a string in a file in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 16:49:32

2K+ Views

To wrap a string in a file in Python, you can follow these steps: Open a file in write mode using the open() function and assign it to a variable. Call the write() function on the file variable and pass the string you want to wrap as an argument. This ... Read More

How do I check if raw input is integer in Python 3?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 14:49:54

3K+ Views

In Python 3, the input() function always returns a string, even if the user enters a number. To check if the user input is an integer, you can use a try-except block and attempt to convert the input string to an integer using the int() function. Here are some code ... Read More

How do I un-escape a backslash-escaped string in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 13:54:07

5K+ Views

In Python, you can un-escape a backslash-escaped string using the decode() method or by using the ast module. Here are few different ways to do it: Using decode() method Example In this method, we define a string called escaped_string that contains a backslash-escaped newline character . We convert this string ... Read More

How do I check if a string has alphabets or numbers in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 13:05:33

2K+ Views

To check if a string has alphabets or numbers in Python, we can use some built-in methods like isalpha() and isdigit(). isalpha() returns True if all characters in a string are alphabets (letters), and False otherwise. isdigit() returns True if all characters in a string are digits (numbers), and False ... Read More

Advertisements