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

posted @ 2016-06-07 17:00  偶尔会寂寞  阅读(106)  评论(0编辑  收藏  举报