#defines a variable as a string containing a format character, and the substitution for that character: x = "There are %d types of people" % 10 #defines a variable as a string: binary = "binary" #defines another variable as a different string: do_not = "don't" #defines one more variable as a string with two format characters, #substituted with a list (containing previously defined variables): y = "Those who know %s and those who %s" % (binary, do_not) #prints the two previously defined complicated string variables: print x print y #reprints the above statements using two different format characters: print "I said: %r." % x print "I also said: '%s'." % y #defines a variable using a logical value: hilarious = False #defines another variable using a string and a format character, but no substitute (yet): joke_evaluation = "Isn't that joke so funny?! %r" #prints one string variable, substituting in the other: print joke_evaluation % hilarious #defines two separate strings: w = "This is the left side of..." e = "a string with a right side." #prints the two strings, conjoined (with no spaces added): 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