随笔分类 - Python
摘要:目录 结构: core |____ __init__.py |____ basic |____ __init__.py |____ database |____ __init__.py |____ mysql |____ __init__.py |____ mysql_db.py |____ tes
阅读全文
摘要:import mathclass Point: def move(self, x, y): self.x = x self.y = y def reset(self): self.move(0, 0) def calculate_dista...
阅读全文
摘要:attributes.pyclass Point: passp1 = Point()p2 = Point()p1.x = 5p1.y = 4p2.x = 3p2.y = 6print(p1.x, p1.y)print(p2.x, p2.y)first_method.pyclass Point:...
阅读全文
摘要:from urllib.request import urlopenhtml = urlopen("http://www.baidu.com")print(html.read())注意: 以上代码基于Python 3.x
阅读全文
摘要:自定义类如下:import mathclass Circle: # Construct a circle object def __init__(self, radius = 1): self.radius = radius def getPerimeter(self): return 2 * self.radius * math.pi def getArea(self): return self.radius * self.radius * math.pi def setRadius(self, ...
阅读全文
摘要:类classPerson:defsetName(self,name):self.name=namedefgetName(self):returnself.namedefgreet(self):print"Hello,I'm%s."%self.nameperson1=Person()person1.setName("David")person1.greet() 运行结果:Hello, I'm David.
阅读全文
摘要:有时候我们的需要制作一些守护进程,如果服务器出现了什么问题,就需要重启某个软件啊之类的那么这类守护进程怎么做呢?请看代码importtimeseconds_to_sleep=2*60while1:#这里你可以利用python的shell做一些系统操作print"HelloDavid,guardprocessisrunning..."time.sleep(seconds_to_sleep)运行方式:cmd进入命令行python 你的python程序名.py
阅读全文
摘要:1. 简单字符串格式化 format = "Hello, how are you doing %s %s!"values = ("David", "Gu")print format % values Result: Hello, how are you doing David Gu! format
阅读全文
摘要:列表示例1: (新建, 删除, 修改) # basic operation of listnames = ['David', 'George', 'Peter', 'Mark', 'ALice']print "Original List:"print namesdel names[1]print "
阅读全文

浙公网安备 33010602011771号