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

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -