python 练习

# -*- coding:utf-8 -*-
#输入一段文字,返回时每个单词首字母为大写
def my_cap(s): # my capitalize fun
    if not isinstance(s,str):
        return
    l = s.split(' ')
    res = ''
    for i in l:
        res += i.capitalize()+' '
    return res
print my_cap(2)

# -*- coding:utf-8 -*-
class Foo(object):
"""docstring for Foo"""
version = 1.0
def __init__(self, nm='John Doe'):
self.name = nm
print 'create Foo '+nm
def showname(self):
print self.name
def showver(self):
print self.version

foo = new Foo()
foo.showname

原文地址:https://www.cnblogs.com/littlehoom/p/5567571.html