🌐
W3Schools
w3schools.com › python › python_operators.asp
Python Operators
Although the + operator is often used to add together two values, like in the example above, it can also be used to add together a variable and a value, or two variables: sum1 = 100 + 50 # 150 (100 + 50) sum2 = sum1 + 250 # 400 (150 + 250) sum3 = sum2 + sum2 # 800 (400 + 400) Try it Yourself » · Python divides the operators in the following groups:
🌐
Stack Overflow
stackoverflow.com › questions › 63591717 › in-python-can-we-use-bitwise-operators-on-data-structures-such-as-lists-tuples
In Python can we use bitwise operators on data structures such as lists, tuples, sets, dictionaries? And if so, why? - Stack Overflow
Those aren't bitwise operators per se. They're operators, and each type can define for itself what it will do with them. The & and | operators map to the __and__ and __or__ methods of an object respectively. Sets define operations for these (intersection and union respectively), while lists do not.
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.8 documentation
6 days ago - The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.,,,, Built-in Functions,,, A, abs(), aiter(), all(), a...
🌐
Reddit
reddit.com › r/learnpython › can you explain this range operator in python?
r/learnpython on Reddit: Can you explain this range operator in python?
February 25, 2024 -
while True:
studRegistered = int(input("Are you registering for Python 101? (Maximum 21 students): "))
if 1 <= studRegistered <= 21:
print(f"Successfully registered {studRegistered} student!")
break  #once input was received
else:
print("Students registered must be between 1 and 21. Please re-enter: ")

Can you explain this scenario. I don't understand why range is written from 1<= studRegistered <21
Why can't (1,21) be used to validate the input? I'm not familiar with that operator.

general-purpose programming language
Python is a high-level, general-purpose programming language that emphasizes code readability, simplicity, and ease-of-writing with the use of significant indentation, an extensive ("batteries-included") standard library, and garbage collection. Python supports multiple programming … Wikipedia
🌐
Python
python.org
Welcome to Python.org
Possible causes include disabled JavaScript or failure to load scripts or stylesheets. ... # Simple arithmetic >>> 1 / 2 0.5 >>> 2 ** 3 8 >>> 17 / 3 # true division returns a float 5.666666666666667 >>> 17 // 3 # floor division 5 · Calculations are simple with Python, and expression syntax is straightforward: the operators +, -, * and / work as expected; parentheses () can be used for grouping.
Top answer
1 of 6
1037

_ has 3 main conventional uses in Python:

  1. To hold the result of the last executed expression in an interactive interpreter session (see docs). This precedent was set by the standard CPython interpreter, and other interpreters have followed suit

  2. For translation lookup in i18n (see the gettext documentation for example), as in code like

    raise forms.ValidationError(_("Please enter a correct username"))
    
  3. As a general purpose "throwaway" variable name:

    1. To indicate that part of a function result is being deliberately ignored (Conceptually, it is being discarded.), as in code like:

      label, has_label, _ = text.partition(':')
      
    2. As part of a function definition (using either def or lambda), where the signature is fixed (e.g. by a callback or parent class API), but this particular function implementation doesn't need all of the parameters, as in code like:

      def callback(_):
          return True
      

      [For a long time this answer didn't list this use case, but it came up often enough, as noted here, to be worth listing explicitly.]

    This use case can conflict with the translation lookup use case, so it is necessary to avoid using _ as a throwaway variable in any code block that also uses it for i18n translation (many folks prefer a double-underscore, __, as their throwaway variable for exactly this reason).

    Linters often recognize this use case. For example year, month, day = date() will raise a lint warning if day is not used later in the code. The fix, if day is truly not needed, is to write year, month, _ = date(). Same with lambda functions, lambda arg: 1.0 creates a function requiring one argument but not using it, which will be caught by lint. The fix is to write lambda _: 1.0. An unused variable is often hiding a bug/typo (e.g. set day but use dya in the next line).

    The pattern matching feature added in Python 3.10 elevated this usage from "convention" to "language syntax" where match statements are concerned: in match cases, _ is a wildcard pattern, and the runtime doesn't even bind a value to the symbol in that case.

    For other use cases, remember that _ is still a valid variable name, and hence will still keep objects alive. In cases where this is undesirable (e.g. to release memory or external resources) an explicit del name call will both satisfy linters that the name is being used, and promptly clear the reference to the object.

2 of 6
263

It's just a variable name, and it's conventional in python to use _ for throwaway variables. It just indicates that the loop variable isn't actually used.

Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › what-does-the-double-star-operator-mean-in-python
What does the Double Star operator mean in Python? - GeeksforGeeks
July 23, 2025 - It is one of the Arithmetic Operator (Like +, -, *, **, /, //, %) in Python and is also known as Power Operator.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-operators
Python Operators - GeeksforGeeks
In Python programming, Operators in general are used to perform operations on values and variables.
Published: 1 month ago
Top answer
1 of 5
386

See Function Definitions in the Language Reference.

If the form *identifier is present, it is initialized to a tuple receiving any excess positional parameters, defaulting to the empty tuple. If the form **identifier is present, it is initialized to a new dictionary receiving any excess keyword arguments, defaulting to a new empty dictionary.

Also, see Function Calls.

Assuming that one knows what positional and keyword arguments are, here are some examples:

Example 1:

# Excess keyword argument (python 3) example:
def foo(a, b, c, **args):
    print("a = %s" % (a,))
    print("b = %s" % (b,))
    print("c = %s" % (c,))
    print(args)
    
foo(a="testa", d="excess", c="testc", b="testb", k="another_excess")

As you can see in the above example, we only have parameters a, b, c in the signature of the foo function. Since d and k are not present, they are put into the args dictionary. The output of the program is:

a = testa
b = testb
c = testc
{'k': 'another_excess', 'd': 'excess'}

Example 2:

# Excess positional argument (python 3) example:
def foo(a, b, c, *args):
    print("a = %s" % (a,))
    print("b = %s" % (b,))
    print("c = %s" % (c,))
    print(args)
        
foo("testa", "testb", "testc", "excess", "another_excess")

Here, since we're testing positional arguments, the excess ones have to be on the end, and *args packs them into a tuple, so the output of this program is:

a = testa
b = testb
c = testc
('excess', 'another_excess')

You can also unpack a dictionary or a tuple into arguments of a function:

def foo(a,b,c,**args):
    print("a=%s" % (a,))
    print("b=%s" % (b,))
    print("c=%s" % (c,))
    print("args=%s" % (args,))

argdict = dict(a="testa", b="testb", c="testc", excessarg="string")
foo(**argdict)

Prints:

a=testa
b=testb
c=testc
args={'excessarg': 'string'}

And

def foo(a,b,c,*args):
    print("a=%s" % (a,))
    print("b=%s" % (b,))
    print("c=%s" % (c,))
    print("args=%s" % (args,))

argtuple = ("testa","testb","testc","excess")
foo(*argtuple)

Prints:

a=testa
b=testb
c=testc
args=('excess',)
2 of 5
210

I only have one thing to add that wasn't clear from the other answers (for completeness's sake).

You may also use the stars when calling the function. For example, say you have code like this:

>>> def foo(*args):
...     print(args)
...
>>> l = [1,2,3,4,5]

You can pass the list l into foo like so...

>>> foo(*l)
(1, 2, 3, 4, 5)

You can do the same for dictionaries...

>>> def foo(**argd):
...     print(argd)
...
>>> d = {'a' : 'b', 'c' : 'd'}
>>> foo(**d)
{'a': 'b', 'c': 'd'}
🌐
Trey Hunner
treyhunner.com › 2018 › 10 › asterisks-in-python-what-they-are-and-how-to-use-them
Asterisks in Python: what they are and how to use them
October 11, 2018 - You need to be careful when using ** multiple times though. Functions in Python can’t have the same keyword argument specified multiple times, so the keys in each dictionary used with ** must be distinct or an exception will be raised.
🌐
YouTube
youtube.com › shorts › z1tXFuG8afE
Did you know about this in Python? - YouTube
🚀 My Software Development Program: https://coursecareers.com/a/techwithtim?course=software-dev-fundamentals&campaign=youtubedescription📬 Join my Newsletter...
Published: April 24, 2025
🌐
Codecademy
codecademy.com › learn › introduction-to-python-dvp › modules › python-syntax-dvp › cheatsheet
Introduction to Python: Python Syntax Cheatsheet | Codecademy
The number 0 represents an integer value, but the same number written as 0.0 would represent a floating point number. ... Python supports the joining (concatenation) of strings together using the + operator. The + operator is also used for mathematical addition operations.
🌐
DataCamp
datacamp.com › tutorial › role-underscore-python
Underscore in Python Tutorial : What is the purpose and meaning of _ & __ | DataCamp
October 26, 2018 - It helps users to write Python code productively. Underscore(_) is a unique character in Python.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-star-or-asterisk-operator
Python - Star or Asterisk operator ( * ) - GeeksforGeeks
April 25, 2025 - The asterisk (*) operator in Python is a versatile tool used in various contexts.
🌐
TikTok
tiktok.com › karina.datascientist (@karinadatascientist) | tiktok › how to change column names to lower case or title case in python #python #coding #dataanalytics #techtok #tecktok
How to change column names to lower case or title case in Python #python #coding #dataanalytics #techtok #tecktok | TikTok
95 Likes, TikTok video from Karina.DataScientist (@karinadatascientist): “How to change column names to lower case or title case in Python #python #coding #dataanalytics #techtok #tecktok”. original sound - Karina.DataScientist.
🌐
Mimo
mimo.org › glossary › python › in-operator
Master Python's in Operator for Various Coding Scenarios
The in operator in Python checks if a specified value exists within a sequence, such as a list, tuple, or string.
🌐
GeeksforGeeks
geeksforgeeks.org › python › underscore-_-python
Underscore (_) in Python - GeeksforGeeks
May 3, 2025 - It is commonly used for name mangling, a technique that helps avoid conflicts in subclass inheritance. The leading double underscore tells the Python interpreter to rewrite the name in order to avoid conflict in a subclass.
🌐
Reddit
reddit.com › r/python › what’s the meaning of single and double underscores in python?
r/Python on Reddit: What’s the Meaning of Single and Double Underscores In Python?
January 25, 2022 -

Have you ever been curious about the several meanings of underscores in Python? A little break-down?

- you can find detailed explanations and code snippets here

1️⃣ single leading underscore ("_var"): indicates that the variable is meant for internal use. This is not enforced by the interpreter and is rather a hint to the programmer.

2️⃣ single trailing underscore ("var_"): it's used to avoid conflicts with Python reserved keywords ("class_", "def_", etc.)

3️⃣ double leading underscores ("__var"): Triggers name mangling when used in a class context and is enforced by the Python interpreter. 
What this means is that it should be used to avoid your method is being overridden by a subclass or accessed accidentally.

4️⃣ double leading and trailing underscores ("__var__"): used for special methods defined in the Python language (ex. __init__, __len__, __call__, etc.). They should be avoided to use for your own attributes.

5️⃣ single underscore ("_"): Generally used as a temporary or unused variable. (If you don't use the running index of a for-loop, you can replace it with "_").