recursion-tree-visualizer icon indicating copy to clipboard operation
recursion-tree-visualizer copied to clipboard

Interpreting strings as variables in python

Open foderking opened this issue 3 years ago • 2 comments

For example, when I use a string "boy", I get an error boy not defined. It is interpreting "boy" as a variable instead of a string. But if I escape the quotes \"boy\" , it works.

foderking avatar Mar 31 '22 12:03 foderking

Do you have some example function?

brpapa avatar Apr 02 '22 16:04 brpapa

Do you have some example function?

literally any function that uses a string

foderking avatar Jun 05 '22 14:06 foderking

I had the same issue [string] not defined, but using 'foo' instead of "foo" works. For example, take a look at this simple string reverse function:

def fn(str):
  if str == "": # this will not work unless you use single quotes insead of double quotes!
    return "" # same problem
  else:
    return fn(str[1:]) + str[0]
fn("abc") # same problem

elfaidi-ghassen avatar Nov 18 '22 20:11 elfaidi-ghassen

Fixed, thanks guys

brpapa avatar Nov 19 '22 16:11 brpapa