About 271,000 results
Open links in new tab
  1. How do I define a name in python? - Stack Overflow

    Feb 21, 2022 · Now, If you really want to know how to define an object in oops in Python, here is the way to do it: First instead of creating a class inside a class, you should just create one …

  2. Python NameError: name is not defined - Stack Overflow

    Feb 11, 2013 · Note that sometimes you will want to use the class type name inside its own definition, for example when using Python Typing module, e.g. class Tree: def __init__(self, …

  3. Convert string to variable name in python - Stack Overflow

    This is the best way, I know of to create dynamic variables in python. my_dict = {} x = "Buffalo" my_dict[x] = 4 I found a similar, but not the same question here Creating dynamically named …

  4. python - Getting the name of a variable as a string - Stack Overflow

    Aug 25, 2013 · Python uses names in the source code to refer to (i.e., give a name to) values. (In many languages, a variable is more like a name for a specific location in memory where the …

  5. python - How do you create different variable names while in a …

    I would personally define a list for your (dynamic) variables to be held and then append to it within a for loop. Then use a separate for loop to view each entry or even execute other operations. …

  6. python - What does if __name__ == "__main__": do? - Stack Overflow

    Jan 7, 2009 · When you run Python interactively the local __name__ variable is assigned a value of __main__. Likewise, when you execute a Python module from the command line, rather …

  7. Methods with the same name in one class in Python

    Jan 5, 2021 · One name refers to one thing. As far as the language is concerned anyway, you can always emulate them yourself... You could check types with isinstance (but please do it …

  8. python - How can you dynamically create variables? - Stack Overflow

    Sep 18, 2021 · $ python b.py name 'B' is not defined __main__ <module '__main__' from 'b.py'> B: 1 But this approach only works in a single module script, because the __main__ it import …

  9. python - Calling a function of a module by using its name (a string ...

    Jun 4, 2022 · Given a string, with a complete python path to a function, this is how I went about getting the result of said function: import importlib function_string = …

  10. python - setting user input to variable name - Stack Overflow

    Apr 23, 2015 · my_name = raw_input("Enter a variable name") # Plain input() in Python 3 localVars = local() localVars[my_name] = 5 If you're inside a function, it can't be done. Python …

Refresh