Articles on Trending Technologies

Technical articles with clear explanations and examples

How do we assign a value to several variables simultaneously in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 7K+ Views

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 More

How do we assign values to variables in a list using a loop in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 7K+ Views

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 More

How I can convert a Python Tuple into Dictionary?

Vikram Chiluka
Vikram Chiluka
Updated on 24-Mar-2026 44K+ Views

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 More

How to find what is the index of an element in a list in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 799 Views

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 More

why Python can\'t define tuples in a function?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 409 Views

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 More

How to add space before and after specific character using regex in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 2K+ Views

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 More

How regular expression grouping works in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 951 Views

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 More

How regular expression back references works in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 1K+ Views

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 More

How not to match a character after repetition in Python Regex?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 493 Views

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 More

How to match a single character in python using Regular Expression?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 2K+ Views

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
Showing 1–10 of 61,302 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements