print('hi') thiswillbetruthy = 1 if thiswillbetruthy: print('dang, smack is truthy!') width = 10 height = 10 print 'height = ' + str(width*height) print 'hei' 'ght' a = b = c = 999 print a #n #since not assigned a value will throw error if used print 'doesn\'t' print "doesn't" print '"Yes," he said.' print "\"Yes,\" he said." print '"Isn\'t," she said.' hello = "This is a rather long string containing\n\ several lines of text just as you would do in C.\n\ Note that whitespace at the beginning of the line is\ significant." print hello print """ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """ hello = r"This is a rather long string containing\n\ several lines of text much as you would do in C." print hello stringforops = 'thisisastringforops' print stringforops[0:2] print stringforops[:2] print stringforops[2:] print stringforops[-2:] print len(stringforops) a = ['spam', 'eggs', 100, 1234] print a[0] a[2] = 'thisis4' print a a[0:2]= [] print a a[:0] = a print a print len(a) a[:] = [] print a p = [1, 2, 3] a = [p, 4, 5, 6] print a print 'abc', 5, 'hi', 7 x = -1 if x > 0: print 'x greater than zero' elif x == 0: print 'x equals zero' elif x < 0: print 'x negative, changing to zero' x = 0 print x
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