Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

underscore in python

"""Use of _ as a variable
It is to indicate throwaway variables, 
...i.e. variables that are not reused anywhere else (as they are...
        ...not logically important) but for syntax reasons you have to put

This saves space for variables that are actually reused...
...and provides a good mental model for essential and unessential parts...
...of your code

Of course, take this as a guideline. 
There are instances where naming those variables are better for readability...
...especially in group projects

Check out the source for more info!
"""

lst1 = [_ for _ in range(10)]
print(lst1)
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Comment

how to use underscore in python

>>> def function(class):
  File "<stdin>", line 1
    def function(class):
                 ^
SyntaxError: invalid syntax
>>> def function(class_):
...     pass
...
>>>
Comment

PREVIOUS NEXT
Code Example
Python :: pyplot savefig 
Python :: matplotlib display graph on jupyter notebook 
Python :: python code with sigma 
Python :: correlation with specific columns 
Python :: PackagesNotFoundError: The following packages are not available from current channels: 
Python :: discord.py send image from url 
Python :: django tempalte tag datetime to timestamp 
Python :: python invert an array 
Python :: how to change frame in tkinter 
Python :: Reading JSON from a File with Python 
Python :: Python, importing other scripts from other directories 
Python :: create a timestamp python 
Python :: pandas cumulative mean 
Python :: python run in another thread decorator 
Python :: hstack 
Python :: flask wtforms multiple select 
Python :: python to executable windows 
Python :: write lines python with line breaks 
Python :: pip install covid 
Python :: how to unlist a list in python 
Python :: print inline output in python 
Python :: replace matrix values python 
Python :: python string format 
Python :: matplotlib set integer ticks 
Python :: python list comprehension 
Python :: Python string to var 
Python :: django textfield 
Python :: Iterate string 2 characters at a time in python 
Python :: sort folders content by name python 
Python :: how to add a value to a list in python 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =