python学习一

1.下载安装python后打开IDLE编辑器输入抓取百度页面代码

from urllib import urlopen
html = urlopen("http://www.baidu.com")
print(html.read())

2.写函数

def printmax(a,b):
    if a>b:
        print a,'is max mum'
    else:
        print b,'is max mun'
printmax(6,4)

3.import包含

 

4.对象的方法

class person:
    def sayHi(self):
        print 'hello,how are you?'
p = person()
p.sayHi()

 5。init相当于php里面的construct,__init__在一个对象被建立时,马上运行

class person:
    def __init__(self,name):
        self.name =name
    def sayhi(self):
        print 'hello,my name is',self.name
p = person('swaroop')
p.sayhi()

 

posted @ 2017-04-11 17:52  qingqing.li  阅读(207)  评论(0编辑  收藏  举报