Pallab
Pallab

Reputation: 2333

How to call a function and print it within quotes?

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

Answers (3)

astrochun
astrochun

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

user14185615
user14185615

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

Robert Axe
Robert Axe

Reputation: 414

You can use different quotes.

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

Upvotes: 1

Related Questions