Interesting "Hello World" Interview

Python 2.x answers

The obvious answer that doesn't actually count because it returns the string instead of printing it:

>>> say = lambda x: lambda y: x + " " + y
>>> say('Hello')('World')
'Hello World'

This one is 45 characters counting newlines:

def p(x):
 print "Hello World"
say=lambda x:p

This method drops it down to 41 characters but it looks kind of odd since it uses one argument but not the other:

def p(x):
 print "Hello",x
say=lambda x:p

Python 3.x answers

36 characters:

>>> say=lambda x:lambda y:print(x+" "+y)
>>> say('Hello')('World')
Hello World

38 characters:

>>> say=lambda x:print(x,end=' ') or print
>>> say('Hello')('World')
Hello World

def say(x):
   print x,
   return say

Tags:

Python