Search code examples
pythondictionarysingle-quotes

remove quotes from output of python dictionaries


I am new to python and I am stuck in a situation here! I have stored strings in a python dictionary and when I try to extract it python is wrapping single quotes around the value and giving it back. How can I get rid of the single quotes?

Example code:

myDict = {"name":"Rosy", "class":"9", "likes":"cakes"}
myDict.get("name")

Output: 'Rosy' Desired output: Rosy


Solution

  • I think you probably just want to:

    print(myDict.get("name"))
    

    note that this isn't specific to dictionaries. when you're in the Python "REPL" (read-eval-print loop) it will call repr (short for representation) on objects to turn them into something that might be helpful when debugging.

    if you're running the script from the command line, lines like you entered don't get displayed and the result gets discarded