#!/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
#同样的效果 更加的简洁