About 298,000 results
Open links in new tab
  1. python - How do I create variable variables? - Stack Overflow

    Is it possible to do something like this in Python? What can go wrong? If you are just trying to look up an existing variable by its name, see How can I select a variable by (string) name?. However, first …

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

    Sep 18, 2021 · I want to create variables dynamically in Python. Does anyone have any creative means of doing this?

  3. Python Variable Declaration - Stack Overflow

    Jun 13, 2012 · The idiomatic way to create instance variables is in the __init__ method and nowhere else — while you could create new instance variables in other methods, or even in unrelated code, …

  4. How can I use a global variable in a function? - Stack Overflow

    Jul 11, 2016 · In Python, the module is the natural place for global data: Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. …

  5. python - How to assign a variable in an IF condition, and then return ...

    Apr 27, 2019 · The one liner doesn't work because, in Python, assignment (fruit = isBig(y)) is a statement, not an expression. In C, C++, Perl, and countless other languages it is an expression, and …

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

    buffalo=4 not only this example, I want to convert any input string to some variable name. How should I do that (in python)?

  7. python - Using a string variable as a variable name - Stack Overflow

    Jul 19, 2012 · I have a variable with a string assigned to it and I want to define a new variable based on that string.

  8. How to declare variable type, C style in Python - Stack Overflow

    Oct 14, 2010 · 12 Python isn't necessarily easier/faster than C, though it's possible that it's simpler ;) To clarify another statement you made, "you don't have to declare the data type" - it should be restated …

  9. python - How can I create an object and add attributes to it? - Stack ...

    May 13, 2010 · I want to create a dynamic object in Python and then add attributes to it. This didn't work: obj = object () obj.somefield = "somevalue" AttributeError: 'object' object has no attribute '

  10. Python: copy of a variable - Stack Overflow

    Nov 24, 2012 · a='hello' b=a #.copy() or a function that will make a copy a='bye' # Is there a way to make # 'b' equal 'a' without # doing 'b=a' print a print b I am having a problem using the Tkinter …