#small comment """ big commment """ print "hi asshole" print "My name is", #a comma after print keeps you on the same line (and adds a space?) print "Matthew." 'It\'s ok to use apostrophes if you use the backslash, too.' some_integer=20 some_float=12.232 some_boolean=True #first letter must be capitalized; True or False print type(some_integer) print type(some_float) print type(some_boolean) #need to use whitespace to write functions, or it won't work def test_fun(): x=1 return x a = test_fun #no value saved b = test_fun() #saves returned value of test_fun function print a print b exponent_math = 2**8 modulo_math = 5%4 #result is remainder of 1 #values in arrays start at the index 0 third_letter = "Test"[2] print third_letter #String Methods string="This is some text" num=32.345 a = len(string) b = string.lower() #dot notation only works on strings c = string.upper() d = str(num) #but this works on other data types e = string.isalpha() #result is False because of spaces print a,b,c,d,e #concatonate print "I " + "love " + "Lucy " + "and the number " + str(42) #insert data into strings a = 1 b = 2 print "The first value is %s and the second is %s" % (a, b) #ask user for input username = raw_input("What is your name?") print " " + username #dates and times from datetime import datetime print datetime.now() print datetime.now().year print datetime.now().month print datetime.now().day print datetime.now().hour print datetime.now().minute print datetime.now().second #importing stuff import math #make math module usable print math.sqrt(9) from math import sqrt # import the sqrt function from math module print sqrt(25) from math import * # import everything from the math module (generally bad idea; hard to keep track of what's from where) import math print dir(math) #varaibles in functions def fun(*val): #expecting any number of values to be input print max(val) print min(val) print abs(min(val)) fun(1,2,3,4,5,6,7,-3,-4,-5,-6) # long list of inputs; length might vary #try / except def anti_vowel(string): out = "" vowels = ["a","e","i","o","u"] for char in string: try: vowels.index(char.lower()) except ValueError: out += char return out print anti_vowel("HELLO WORLD!")
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