Capitalise every other letter in a string in Python? -


i've been trying define function capitalise every other letter , take spaces accout example:

print function_name("hello world") should print "hello world" rather "hello world"

i hope makes sense. appreciated.

thanks, oli

def foo(s):     ret = ""     = true  # capitalize     char in s:         if i:             ret += char.upper()         else:             ret += char.lower()         if char != ' ':             = not     return ret  >>> print foo("hello world") hello world' 

Comments

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -