您的位置:首页 > 编程语言 > Python开发

python学习:函数传参数

2017-09-13 17:54 225 查看
#!/usr/bin/python

import sys

def isNum(s):
for i in s:
if i in '0123456789':
pass
else:
print "%s is not a number" %s
sys.exit()
else:
print "%s is a number" %s

isNum(sys.argv[1])

//函数判断是否为数字

执行结果:
python 12.py aa
aa is not a number
[root@web10 day02]# python 12.py 123
123 is a number
[root@web10 day02]# python 12.py 123d
123d is not a number

#!/usr/bin/python

import sys
import os

def isNum(s):
if s.isdigit():
return True
return False

for i in os.listdir('/proc'):
if isNum(i):
print i
#同样的效果 更加的简洁
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: