-1
    import random
list = ['p','s','r']

chance = 10
no_of_chance = 0
computer_point = 0
human_point = 0

print(" \t \t \t \t paper,scissor,rock Game\n ")
print("p for paper \n s for scissor \n r for rock ")


while no_of_chance < chance:
    _input = input('p or s or r:')
    _random = random.choice(list)
  1. This is a paper scissor rock python code,i found online.I pasted part of a code here.I could not understand why there is underscore in front of the input and random. i am beginner in python so kindly help me.
  • Does this answer your question? [Does Python have “private” variables in classes?](https://stackoverflow.com/questions/1641219/does-python-have-private-variables-in-classes) – sushanth Jun 08 '20 at 05:34
  • The underscore is a naming convention in Python - read https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables – Grismar Jun 08 '20 at 05:34
  • It's your choice you can use whatever name you want but just see to it that you don't declare two or more vars with same name. – JenilDave Jun 08 '20 at 06:15

2 Answers2

0

When it comes to variable and method names, the single underscore prefix has a meaning by convention only. It’s a hint to the programmer—and it means what the Python community agrees it should mean, but it does not affect the behavior of your programs.

The underscore prefix is meant as a hint to another programmer that a variable or method starting with a single underscore is intended for internal use. This convention is defined in PEP 8.

Kuldeep Singh Sidhu
  • 3,748
  • 2
  • 12
  • 22
0

Naming convention indicating a name is meant for internal use. Generally not enforced by the Python interpreter (except in wildcard imports) and meant as a hint to the programmer only.