Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (47.6k 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 (106k 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:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 3 in Python by ashely (50.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...