Data conversion in Python refers to changing the data type of a value to another data type. Python supports two different types of data conversion, such as Implicit conversion and explicit conversion. Implicit Conversion is performed by the Python interpreter automatically. Explicit Conversion is manually done by the programmer using built-in functions in Python Implicit Conversion Python automatically converts one data type to another, and this type of conversion is called Implicit conversion. To avoid any data loss during runtime, the smaller data type is converted ... Read More
A non-whitespace character is any character that is not a space, tab i.e., \t, newline i.e., or carriage return \r. Examples of non-whitespace characters such as letters, digits, punctuation and special symbols. In Python, Regular Expressions (RegEx) are used to match the patterns in the given input strings. The re module in Python provides different methods to use the regular expressions. This module helps the developers to perform search operations, validations, filtering and much more based on string patterns. To match a non-whitespace character in Python we can use the special character class \S inside a raw string in any ... Read More
In Python, Regular expressions are also called RegEx, which is a sequence of characters that defines a search pattern. The re module provides several functions to work with patterns in text. This is widely used in Python tasks such as string matching, validation, and manipulation. The most commonly used functions in the "re" module are re.match() and re.search(). These two methods are used to check for the presence of a pattern, but they differ in the way they look for a pattern match within a string. In this article, we are going to see the difference between the Python re.search() ... Read More
In Python, a Dictionary is one of the data structures that contains key-value pairs enclosed in curly braces '{}'. It is a Mutable and ordered data structure. Before proceeding with updating the values of a dictionary, let's create an example Dictionary with 4 key-value pairs, in which Product, Model, Units, are keys of the Dictionary - # Creating a Dictionary with 4 key-value pairs myprod = { "Product":"Mobile", "Model": "XUT", "Units": 120, "Available": "Yes" } # Displaying the Dictionary print(myprod) # Displaying individual values ... Read More
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
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
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
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
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
To find how many characters are present in a string (i.e. length of a string), Python provides the built-in function named len(). The length includes all characters in the string, including spaces, punctuation, and special characters. Using len() Function The len() function is the most direct way to find out how many characters are in a string. It returns the total number of characters, including spaces and special symbols. Example In the following example, we are calculating the length of a string using the len() function - text = "Python Programming" length = len(text) print("Length of the string is:", length) ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP