-3

What is the meaning of , _ in the following Pyhyhon code?

 file_name, _ = QFileDialog.getSaveFileName(self, 'Save File',
            "","All Files (*);;Text Files (*.txt)")
user3489173
  • 45
  • 1
  • 9
  • 1
    ```_``` is a variable name here. You can use any valid variable name. The function returns two instances. One is stored in ```file_name``` and another is in ```_``` – ksohan Jan 03 '22 at 00:32
  • 1
    Does this answer your question? [What is the purpose of the single underscore "\_" variable in Python?](https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python) – kirjosieppo Jan 03 '22 at 00:33
  • The comma means the function returns a sequence of two values. `file_name` is assigned the first value, and `_` is assigned the second. – John Gordon Jan 03 '22 at 00:42

1 Answers1

4

_ is a name for a variable like anything else, but typically used to indicate that it won't be used. Think of it as file_name, some_useless_variable = ...

Julien
  • 13,986
  • 5
  • 29
  • 53