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 on Trending Technologies
Technical articles with clear explanations and examples
How do we assign a value to several variables simultaneously in Python?
Python is not a "statically typed" programming language. We do not need to define variables or their types before utilizing them. Once we initially assign a value to a variable, it is said to be created. Each variable is assigned with a memory location. The assignment operator (=) assigns the value provided to right to the variable name which is at its left. The syntax of the assignment operator is shown below − var_name = value Example of Assignment Operator The following is an example that shows the usage of the assignment operator − ...
Read MoreHow do we assign values to variables in a list using a loop in Python?
In Python, lists are a useful way to store multiple elements in a single variable. To assign values to each entry in a list, loops are often needed. This strategy simplifies the process and improves the clarity of your code. This chapter will look at how to assign values to variables in a list using different loop types, using basic examples. Using Simple Loop Iterations In this method, we use the while loop to continuously prompt the user for input and append elements to the list. When we do not enter any element into the list and just ...
Read MoreHow I can convert a Python Tuple into Dictionary?
The Python tuple elements are enclosed inside the parentheses, while dictionary elements are present in the form of a key-value pair and are enclosed between curly brackets. In this article, we will show you how to convert a Python tuple into a dictionary. The following are the methods to convert a tuple into a dictionary − Using dict() Function Using Dictionary Comprehension and enumerate() Function ...
Read MoreHow to find what is the index of an element in a list in Python?
In Python, an index is an element's location within an ordered list. The first entry has a zero index, and the last element has an n-1 index, where n is the length of the list. In this tutorial, we will look at how to find the index of an element in a list in Python. There are different methods to retrieve the index of an element. Using index() Method The list index() method in Python accepts three arguments − element: element that has to be found. start ...
Read Morewhy Python can\'t define tuples in a function?
The title "why Python can't define tuples in a function?" contains a misconception. Python can define tuples in functions perfectly well. This article will clarify how to work with tuples in functions, showing various ways to create, return, and manipulate tuples within functions. A tuple is an ordered, unchangeable collection of items in Python. Once created, its values cannot be modified. Tuples are defined with parentheses "()" and can store multiple data types. Basic Tuple Creation Here is how you define a tuple ? # Defining a tuple my_tuple = (1, 2, 3) print(my_tuple) print(type(my_tuple)) ...
Read MoreHow to add space before and after specific character using regex in Python?
When working with text data in Python, we often need to format strings to make them more readable. Regular expressions (regex) provide a powerful way to add spaces before and after specific characters. In this article, we'll explore how to use Python's re module for this purpose. Understanding the Regex Pattern The key to adding spaces around characters is using the re.sub() function with the pattern r'\s*character\s*'. This pattern: \s* − Matches zero or more whitespace characters before the target character character − The specific character we want to format \s* − Matches zero or more ...
Read MoreHow regular expression grouping works in Python?
Regular expression grouping in Python allows you to capture specific parts of a pattern match using parentheses (). This feature is essential for extracting structured data from strings and organizing match results into meaningful components. Understanding Regex Grouping Basics Groups are created by placing parentheses around parts of your regex pattern. The re module provides two main methods for working with groups ? group() − Returns the whole match or a specific group by number groups() − Returns all captured groups as a tuple Syntax import ...
Read MoreHow regular expression back references works in Python?
Backreferences in regular expressions allow us to reuse a previously captured group within the same regex pattern. This feature is extremely useful for matching repeated patterns, validating formats, and finding duplicates in strings. What are Backreferences? A backreference is a reference to a previously captured group in a regular expression. When parentheses "()" are used in a regex pattern, they create a capturing group. Each group is automatically assigned a number starting from 1 for the first group, 2 for the second, and so on. Syntax Here's the basic syntax for using backreferences ? ...
Read MoreHow not to match a character after repetition in Python Regex?
Regular expressions (regex) are powerful tools in Python for pattern matching and text processing. Sometimes you need to match a pattern but exclude cases where specific characters follow after repetition. This is achieved using lookahead assertions that check what comes next without including it in the match. Understanding re.findall() Function The re.findall() function searches for all occurrences of a pattern in a string and returns them as a list. It takes two main parameters: the pattern to search for and the string to search in. Syntax import re re.findall(pattern, string) Using Positive ...
Read MoreHow to match a single character in python using Regular Expression?
A single character can be matched in Python using a regular expression. A regular expression is a sequence of characters that helps you find a string or a set of strings using a search pattern. Regular expressions are also known as RegEx. Python provides the re module that is used to work with regular expressions. The Dot (.) Metacharacter The dot . is a special metacharacter in regular expressions that matches any single character except newline. It's the most common way to match a single character in a pattern. Using findall() Function The findall() function searches ...
Read More