Python Warts

misfeatures and other problems
PERL| PHP| PYTHON| RUBY
What do each of the following programs do? (all answers)
Question 1: (answer)
#!/usr/bin/python

i=1
def f():
	print "i=%s" % i
	i = i + 1 

f()
answer
Question 2: (answer)
#!/usr/bin/python

def outer():
	i=1
	def inner():
		print "i=%s" % str(i)
		i += 1
	
	inner()
	inner()

outer()
answer
Question 3: (answer)
#!/usr/bin/python

def add_evil(data=[]):
	data.append(666)
	return data

print add_evil()
print add_evil(["hi there"])
print add_evil()
print add_evil()
answer
Question 4: (answer)
#!/usr/bin/python

a = [1,2,3]
b = a

a += [4]
b = b + [5]

print "a=%s" % a
print "b=%s" % b
answer
Question 5: (answer)
#!/usr/bin/python

a = ([1,2,3], [7,8,9])

try:
	a[0] += [4,5,6]
except Exception, e:
	print "Error: %s" % e

print "a=%s" % str(a)
answer
PERL| PHP| PYTHON| RUBY
Last modified: March 30, 2006 @ 7:04 MST
Copyright (C) 1996-2017 Selene Scriven