First knowledge of Python 4

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.