Python入门的36个例子 之 18
例1:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 019
# 使用“import”语句调用模块:
import _018_Module
_018_Module.func1()
_018_Module.func2()
_018_Module.func3()
output:
This is function 1.
This is function 2.
This is function 3.
例2:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 020
# 使用“from ... import ...”语句调用模块
from _018_Module import func2
import _018_Module
_018_Module.func1()
func2()
_018_Module.func3()
output:
This is function 1.
This is function 2.
This is function 3.
例3:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 021
# 使用“from ... import *”语句调用模块
from _018_Module import *
func1()
func2()
func3()
output:
This is function 1.
This is function 2.
This is function 3.
相关文档:
from: http://www.cnblogs.com/dahuzizyd/archive/2005/03/01/111006.html
python支持面向对象的编程风格,这里主要说说python中的多继承:
下面的代码使用python2.4,安装后使用idle的IDE开发环境(说是IDE ,比起delphi,VS.net等简单得太多了)
从File-New菜单建立一个.py文件,写下面的代码:
class SuperCl ......
最近对python产生了兴趣,于是从网上下载了基本PYTHON的书和文档,开始了PYTHON的学习,发现PYTHON中的list对象的功能实在是非常强大,编程起来比其他的程序语言对列表的操作要方便的多。
在python中定义一个列表只需要如下语句
li = ["a","b","c","d"]
list有许多的函数可以用来进行对列表的操作,如extend,append,inse ......
1. Basic
参考《Python正则表达式操作指南》
模块re,perl风格的正则表达式
regex并不能解决所有的问题,有时候还是需要代码
regex基于确定性和非确定性有限自动机
2. 字符匹配(循序渐进)
元字符
. ^ $ * + ? { [ ] \ | ( )
1) "[" 和 "]"常用来指定一个字符类别,所谓字符类别就是你想匹配的一个字符集。如[ ......
关于C++和Python之间互相调用的问题,可以查找到很多资料。本文将主要从解决实际问题的角度看如何构建一个Python和C++混合系统。
&nbs ......
# 015
# 默认参数的本质是:
# 不论你是否提供给我这个参数,我都是要用它,
# 那么我就要想好在你不向我提供参数的时候我该使用什么。
# 或者,这样来理解:
# 有一些参数在一般情况下是约定俗成的,
# 但,在极少情况下会有一些很有个性的人会打破传统而按照自己的习惯来做事
def theFirstDayInAWeek(theDay = 'Sunda ......