function definition:
def fun ()
[Email protected] ~]# vim fun.py
#!/usr/bin/python
def fun ():
STH = raw_input ("Please input something")
Try
if Type (int (sth)) ==type (1):
Print "%s is a number"%sth
Except ValueError:
Print "%s is not number"%sth
Fun ()
[email protected] ~]# python fun.py
Please input SOMETHING34
is a number
[email protected] ~]# python fun.py
Please input SOMETHINGDF
DF is not number
Python Pass parameters
[Email protected] ~]# vim isnum.py
#!/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]) #argv [1] refers to 12 or abc,argv[0] refers to isnum.py
[[email protected] ~]# Python isnum.py 12
is a number
[[email protected] ~]# python isnum.py ABC
ABC is not a number
This article comes from "Plum blossom fragrance from bitter cold!" "Blog, be sure to keep this provenance http://daixuan.blog.51cto.com/5426657/1774533
Python Learning Note 4-functions