# This is how you find a specified something within another specified something def get_swag(x, y): if y in x: y = x.index(y) print x[y] else: print "That isn't in there." # This is how to check whether something is an integer or not def check_num(k): if isinstance (k, (int, long)): #Command "isinstance" checks the variable for its classinfo print k, "is an integer." else: print k, "is not an integer." # This is how to run a check of integers on a list. def run_check_num(a): if isinstance(a, list): # Now my function can check lists and individual variables if len(a) == 0: print "Whoops, nothing in the list." return place = 0 while place < len(a): if check_num(a[place]): place = place + 1 else: place = place + 1 else: check_num(a) thislist = ["five", 7, 7, "YOUR MOM", "#SWAG"] hi = [] get_swag(thislist, "YOUR MOM") get_swag(thislist, "ALL I WANT FOR MY BIRTHDAY IS ABIG BOOTY HO.") print "\n" print "If you check a list for numbers, you get a list." run_check_num(thislist) print "If it's an empty list, you get this." run_check_num(hi) print "If you put an integer in, you get one answer." run_check_num(8) print "And as for the false answer:" run_check_num("FUCK YOU")
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