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 ......
在网上搜不到关于 Ascii 和 bcd互相转化的文章,于是自己写了一个,和大家分享下。
没有考虑到效率,能够优化的地方望大家提出
"""
AscII字符转换为BCD字符
"""
def asc2bcd(inAsc, pad_L0_R1 = 0):
#全部转换为大写,为后面的转换提供方便
inAsc = inAsc.upper()
&nb ......
关于C++和Python之间互相调用的问题,可以查找到很多资料。本文将主要从解决实际问题的角度看如何构建一个Python和C++混合系统。
&nbs ......
二元运算符及其对应的特殊方法
二元运算符
特殊方法
+
__add__,__radd__
-
__sub__,__rsub__
*
__mul__,__rmul__
/
__div__,__rdiv__,__truediv__,__rtruediv__
//
__floordiv__,__rfloordiv__
%
__mod__,__rmod__
**
__pow__,__rpow__
<<
__lshift__,__rlshift__
>>
_ ......
# 004
# 利用三引号(''' or """)可以指示多行字符串
print '''line1
line2
line3'''
# 另外,你还可以在三引号中任意使用单引号和双引号
print ''' "What's up? ," he replied.'''
# 否则,你好使用转义符来实现同样的效果
# 还是使用三引号好,不然就破坏了视觉美了
print ' \"Wha ......