
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 33578 Articles for Programming

2K+ Views
In Python, we can join two strings into one single string using different ways, such as - Using the + Operator Using the join() Method Using Formatted Strings String Concatenation in Loops Let us look at each method with examples. Using + Operator The most common way to combine two strings into one in Python is by using the + operator. It joins the strings exactly as they are, without any space or separator in between. Example In the following example, we ... Read More

42K+ Views
In this article, we are going to find out how to check if a character is an uppercase letter in Python. We will explore four different approaches - Using the isupper() method Using regular expressions Using ASCII values Direct comparison In each approach, we will check whether a given character is in uppercase and return True or False accordingly. Using the isupper() Method The first and most straightforward way is by using the built-in isupper() method. This method returns True if the ... Read More

4K+ Views
In this article, we are going to focus on how to check if the text is empty (spaces, tabs, newlines) in Python. Checking if text is Empty using isspace() method The isspace() method determines whether a string contains only spaces or contains any other characters. If the given string is only made up of spaces, this method returns true; otherwise, it returns false. Even if the string contains characters like t and n, the method returns true. Example In the program given below, we are taking 3 different strings and finding out if they contain only spaces using the isspace() ... Read More

12K+ Views
A string is considered to contain only whitespace if it consists entirely of characters like space (' '), tab ('\t'), newline (''), carriage return ('\r'), etc. Python provides ways to check this directly using built-in functions or regular expressions. Using isspace() Method The isspace() method returns True if all characters in the string are whitespace characters and the string is not empty. If there is any non-whitespace character, it returns False. Example: Only Whitespace In the following example, the string contains a few spaces and tab characters, so the isspace() method returns True - str1 = " \t ... Read More

9K+ Views
Checking for Uppercase Letters in Python A string is considered to contain only upper-case letters if all its characters are alphabets and each one is in upper case (from 'A' to 'Z'). Python provides various ways to check this, such as using the isupper() method, regular expressions, or manually checking each character. Using isupper() Method The isupper() method returns True if all the alphabetic characters in the string are uppercase and there is at least one alphabet. If the string contains any lowercase letters or non-alphabetic characters, it returns False. Example: All Uppercase Letters In the following example, the string ... Read More

4K+ Views
Checking for Lowercase Letters in PythonIn Python, a string is considered to have only lower-case letters if all its characters are alphabets and each one of them is in lower case (from 'a' to 'z'). We can verify this using the built-in islower() method, regular expressions, or by checking each character using the all() method. Using islower() Method The islower() method returns True if all the characters in the string are in lowercase and there is at least one alphabet. If the string contains uppercase letters or non-alphabetic characters, it returns False. Example: All Lowercase Letters In the following example, ... Read More

7K+ Views
In Python, strings can contain letters, numbers, or special characters. To check if a string is alphanumeric (contains only letters and numbers), we can use different methods. This article shows three simple ways to do that: Using the isalnum() function Using regular expressions Using the isalpha() and isdigit() functions Using the isalnum() Function The isalnum() method returns True if all characters in the string are letters or digits; otherwise, it returns False. Example: Basic Alphanumeric Check In the example below, we take two strings and check if they contain only alphabets and numbers using the isalnum() function: str1 ... Read More

275 Views
For the given code above the solution is as followsExampleclass CustomValueError(ValueError): def __init__(self, arg): self.arg = arg try: a = int(input("Enter a number:")) if not 1 < a < 10: raise CustomValueError("Value must be within 1 and 10.") except CustomValueError as e: print("CustomValueError Exception!", e.arg)OutputEnter a number:45 CustomValueError Exception! Value must be within 1 and 10. Process finished with exit code 0

882 Views
A suffix is a group of letters added at the end of a word. In Python, we can check if a string ends with any one of multiple suffixes using the endswith() method. It takes a tuple of suffixes as an argument and returns True if the string ends with any of them. This is useful for checking file extensions, URL endings, or word patterns. Using endswith() with Multiple Suffixes The endswith() method allows you to check if a string ends with any one of several suffixes by passing them as a tuple. This helps to check for multiple ... Read More

2K+ Views
You cannot directly use an if statement to catch exceptions in Python. Instead, use a try-except block and place if conditions inside the except to respond differently based on the type or message of the exception. This allows you to write conditional logic for exception handling. Using if Inside the except Block You can write if conditions inside the except block to check the type or details of the exception and take appropriate action. Example: Matching Exception Message with "if" In this example, we catch a ValueError and use if statement to inspect its message - def process_input(value): ... Read More