0 votes
1 view
in Python by (47.8k points)

Ruby example:

name = "Spongebob Squarepants"

puts "Who lives in a Pineapple under the sea? \n#{name}."

The successful Python string concatenation is seemingly verbose to me.

1 Answer

0 votes
by (107k points)
edited by

If you are a user of Python 3 then yes it has the string interpolation similar to Ruby's string interpolation. Talking about the version of Python which is released by the end of 2016 there, you will be able to include expressions in "f-strings".

An example that shows how to use f-string:-

name = "abobebmjb abobebmjb"

print(f"Who lives in mango under the river? {name}.")

image

If you are a user of Python 2.Xthen you can use the .format() function below is the code for the same:

"my {0} string: {1}".format("cool", "Hey there!")

image

To know more about this you can have a look at the following video tutorial:-

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...