how to use underscore in python code example
Example 1: how to use underscore in python
def public_api():
print ("public api")
def _private_api():
print ("private api")
Example 2: how to use underscore in python
class Prefix:
... def __init__(self):
... self.public = 10
... self._private = 12
>>> test = Prefix()
>>> test.public
10
>>> test._private
12
Example 3: how to use underscore in python
>>> class MyClass():
... def __init__(self):
... print ("OWK")
>>> def my_defination(var1 = 1, class_ = MyClass):
... print (var1)
... print (class_)
>>> my_defination()
1
__main__.MyClass
>>>
Example 4: how to use underscore in python
for _ in range(10)
print ("Test")
a,b,_,_ = my_method(var1)
Example 5: how to use underscore in python
>>> def function(class):
File "<stdin>", line 1
def function(class):
^
SyntaxError: invalid syntax
>>> def function(class_):
... pass
...
>>>