Function: Determine if it is a number
Law One:
VI 11.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 ()
Save and exit
[[email protected] day2]# python 11.py
Please input something:45
is a number
-----------------------------------------------
Law II:
[Email protected] day2]# VI 12.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])
Save and exit
[[email protected] day2]# Python 12.py 123
123 is a number
[[email protected] day2]# python 12.py 123kh
123kh is not a number
--------------------------------------
Print System process number
VI 13.py
#! /usr/bin/python
Import Sys
Import OS
def isnum (s):
For I in S:
If I not in ' 0123456789 ':
Return False
Return True
For I in Os.listdir ('/proc '):
If Isnum (i):
Print I
Save and exit
[[email protected] day2]# python 13.py
1
2
3
This article from "Knowledge Change Destiny" blog, declined reprint!
First knowledge of Python 4