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
#同样的效果 更加的简洁
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
#同样的效果 更加的简洁
相关文章推荐
- 【python学习资料】各种python 函数参数定义和解析 --转载自byte_way
- Python学习笔记5:函数参数详解
- python学习:函数的参数
- python学习笔记-(13)python中的函数参数传递
- Python学习之基础语言篇——函数参数详解
- Python新手学习基础之函数-可变参数*
- Python学习笔记——函数参数
- 谭子python学习笔记--函数的参数
- 【Python】学习笔记十三:函数的参数对应
- Python学习笔记7-把函数当参数传递、指定可变参数
- Python3学习笔记05-字典、文件输入输出、模块、函数参数传递
- Python学习19:其他应用(列表综合、列表或元组作为函数参数、lambda形式)
- Python学习--定义函数及参数传值
- Python新手学习基础之函数-关键字参数
- 【Python】学习笔记——-3.3、函数的参数
- Python学习(10)--函数的调用和参数
- Python学习笔记7-把函数当参数传递、指定可变参数
- 【Python学习日记】函数 和 参数
- 王亟亟的Python学习之路(五)-dictionary,set,函数,函数参数
- python学习——函数的参数