Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Nikitasha Shrivastava
52 articles
Python Functions creating iterators for efficient looping
In this article, we will talk about creating iterators for efficient looping in Python functions. An iterator is an object that helps you go through all items one by one, like reading pages of a book sequentially. In Python, we can use lists, tuples, dictionaries, and sets as iterables. Let's explore Python functions that generate iterators for efficient looping and memory management. What are Iterators? An iterator is an object that implements the iterator protocol, consisting of __iter__() and __next__() methods. Iterators are memory-efficient because they generate values on demand rather than storing all values in memory ...
Read MoreDecimal fixed point and floating point arithmetic in Python
This article will explain how decimal fixed-point and floating-point arithmetic work in Python, which is useful for performing accurate calculations in various applications. Numbers in Python can be stored in two ways: floating-point and decimal fixed-point. Floating-point numbers are fast but can sometimes be imprecise because of how computers store them in binary. On the other hand, Decimal fixed-point numbers are more accurate and useful when working with precise calculations. By the end of this article, you will understand how both types of numbers work, when to use them, and how to write programs using them. Floating-Point ...
Read MoreHow to extract data from a string with Python Regular Expressions?
In this article you will find out how to extract data from a string with Python Regular Expressions. In Python, extracting data from the given string is a common task. Regular expressions (regex) offer pattern-matching functionality to get and identify specific parts of a string. Python's re module helps in working with regex easily. The common functions of this module are re.search(), re.findall() and re.match() to make it easier to extract desired data. Common Regular Expression Functions Function Purpose Returns re.findall() Find all matches List of strings re.search() Find first match ...
Read MoreHow to write a Python regular expression that matches floating point numbers?
This article will discuss how to write a Python regular expression that matches floating point numbers. We will try to create a regular expression pattern that can match any floating point number. A regular expression for floating point numbers should match integers and floating point numbers where the integer part might be optional. A floating-point number can look like ? Whole numbers with decimals like 3.14, 1.5, 12.10 Negative numbers like -2.55, -1.003 Numbers with optional zeros like 007.5, .75 Basic Regex Pattern for Floating Point Numbers Here is the regular expression pattern for ...
Read MoreHow to write a Python Regular Expression to validate numbers?
Regular expressions provide powerful pattern matching for validating different number formats in Python. The re module offers functions like re.match() to check if strings conform to numeric patterns. There are several common approaches to validate numbers using regular expressions ? Validate Integer Numbers Validate Real Numbers (Decimals) Validate Comma-Separated Numbers Validate Integer Numbers To validate integers, we use the pattern ^[+-]?\d+$ which matches optional sign followed by one or more digits ? import re # Test different integer values numbers = ["123", ...
Read MoreHow to write a Python regular expression to use re.findall()?
This article will explain how to write a Python regular expression to use re.findall() method. Regular expression, or regex, is used in searching and extracting patterns in text. Python provides the re module to work with regex, and re.findall() to find all matches of a pattern in a string. The re.findall() method returns a list of all occurrences of a pattern. It works with strings for extracting data and supports metacharacters for pattern matching. There are various ways to use the re.findall() method in Python, such as − Find One or More Digits Find All Words ...
Read MoreHow do backslashes work in Python Regular Expressions?
Backslashes in Python regular expressions (regex) are used to define special sequences and escape characters. As backslashes are also used in Python strings, we need to be careful while using them. How Backslashes Work Here's how backslashes function in Python regular expressions − Escaping Characters: Some characters have specific meanings in regex (such as . or *). To treat them as normal characters, use a backslash (\.). ...
Read MoreHow to use range in Python regular expression?
In this article, you will find out how to use the range in Python regular expressions. With the help of Python's regular expressions, you can search, match, and manipulate text efficiently. One useful feature in regex is ranges, which helps us define sets of characters within square brackets "[ ]". Range in Regex In Python, a range is used when you want to match characters within a specific group. It is defined inside brackets "[ ]" with the help of a hyphen −. For example: # Matches any digit (0 to 9) pat1 = r"[0-9]" ...
Read MoreHow to write Python Regular Expression find repeating digits in a number?
In this article, you will learn to write regular expressions in Python to find repeating digits in a given number. Regular expressions are a powerful feature that helps you find matching patterns in strings. Finding repeating digits is useful in many areas like data validation, pattern recognition, and number analysis. For example, in the number 1223, we can identify that "22" contains repeating digits. Understanding the Regex Pattern To find repeating digits, we use the pattern r'(\d)\1+': (\d) − Captures a single digit in a group \1+ − Matches one or more occurrences of the ...
Read MoreHow to capture an exception raised by a Python Regular expression?
This article provides a guide on how to capture exceptions raised by regular expressions in Python. We will explore simple example programs that demonstrate proper error handling techniques. Regular expressions are useful for matching patterns in text, but they may result in errors like incorrect syntax or mismatches. Python uses exception handling (try-except blocks) to handle these errors gracefully and prevent program crashes. For example, if the given pattern is "[a-z", this is an incorrect pattern that will raise an error because the closing bracket "]" is missing from the character set. Python Regex Exception Type ...
Read More