0

I am reviewing this code, but I am not sure what _ = input() is for in python.

Here you are the code:

class Difference:
    def __init__(self, a):
        self.__elements = a
        self.maximumDifference = 0

# End of Difference class

_ = input()
a = [int(e) for e in input().split(' ')]

d = Difference(a)
d.computeDifference()

print(d.maximumDifference)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • its a variable that the coder is saying will not be used. its just like saying var = foo() – Ritwick Jha Jun 21 '22 at 18:21
  • If I'm right the _ use when you want a variable but won't use it – WhiteAB Jun 21 '22 at 18:22
  • 1
    `_` is a legal variable name; it's conventionally used to indicate a variable whose value you won't use after its value is assigned. – chepner Jun 21 '22 at 18:22
  • 3
    Whatever input the author of the code is expecting, they don't care about the first line of it. My guess is it's the number of integers to expect on the following line. If the input is for some sort of coding challenge, either it's necessary or convenient in some languages to know how many space-separated values will be found on the second line. In Python, `str.split` handles it for you, so you typically can just ignore the value. – chepner Jun 21 '22 at 18:23

0 Answers0