x = "There are %d types of people in the world." % 10 Binary = "binary" DoNot = "don't" y = "Those that know %s and those that %s." % (Binary, DoNot) # On the variable line the formatting is already done so they are filled when printed. print x print y # %r or repr() automatically puts single quotes around what is printed. # %s or str() does not put single quotes around what is printed so you have to do it manually. print "I said: %r." % x print "I also said: '%s'" % y Hilarious = False # Apparently even if a variable isn't entered as a string it can still be printed as one. JokeEvaluation = "Isn't that so funny? %r" # The %r in JokeEvaluation is filled by the Hilarious variable. # Also the fact that the %r is in a string does not mean it can't be activated. print JokeEvaluation % Hilarious w = "This is the left side..." e = "of a string with a right side." # The + does not put spaces between the printed segments. print w + e
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question