Reputation: 2333
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?
Upvotes: 3
Views: 670
Reputation: 1796
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.
Upvotes: 4
Reputation:
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)
Upvotes: 0
Reputation: 414
You can use different quotes.
value = '$350'
print(f'"{value}"')
Upvotes: 1