How to call a function and print it within quotes?

Viewed 174

I would like to print two parameters of a function inside double quotes, something like this

def convert_to_currency(a,b):
    print (a,b)
convert_to_currency("$",350)

The output that I am getting is $350.

But, I would like to get the output as "$350".

How do I do this with this function?

3 Answers

For Python 3.6+, use f strings.

Since you are requiring two inputs, I'll borrow from @robert-axe response:

def convert_to_currency(a, b):
    print(f'"{a}{b}"')


convert_to_currency("$", 350)

Note the set of single and double quotes here. This will print the string with quotes. You can use a different currency symbol in a still.

You can use different quotes.

value = '$350'
print(f'"{value}"')

Or you could use backslashes to cancel out (disable) the double qoute, like this.

def convert_to_currency(a, b):
    print ("\"", a, b, "\"")
convert_to_currency("$", 350)
Related