Rajendra Dharmkar has Published 496 Articles

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

Rajendra Dharmkar

Rajendra Dharmkar

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

357 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

492 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

113 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

323 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

6K+ 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

2K+ 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 to capitalize a string in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 17:13:52

92 Views

Capitalizing a string in Python is a common task and can be done using methods like upper(), capitalize() and others. Here are some examples of how to use it: Capitalize all the letters in a string Example In this example, we define a string "lorem ipsum" and use the upper() ... 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

874 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 Python modules work?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 10-Aug-2023 14:59:15

205 Views

Python modules are essentially just files containing Python code that can be imported and used in other Python programs. Here's an explanation with some code examples: Basic Module Example Let's create a simple module called my_module.py. We can define a function in this module called hello() which prints a ... 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

198 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

Advertisements