【Python 2.6.6】简单的自定义函数
测试环境
1 2 3 4 5 |
[root@dt xxf]# python Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> |
创建Python自定义函数,保存到文件hello.py,函数基本语法如下:
def + 函数名字 + 参数 +冒号
具体动作
例如:
1 2 3 4 |
def hello(name): print 'hello ' + name hello('DBA!') |
执行效果
1 2 3 |
[root@dt xxf]# python hello.py hello DBA! [root@dt xxf]# |