The procedure is as follows:
[Python]
#! /Usr/bin/env python
Import sys
Def search2 (a, m ):
Low = 0
High = len (a)-1
While (low <= high ):
Mid = (low + high)/2
Midval = a [mid]
If midval <m:
Low = mid + 1
Elif midval> m:
High = mid-1
Else:
Print mid
Return mid
Print-1
Return-1
If _ name _ = "_ main __":
A = [int (I) for I in list (sys. argv [1])]
M = int (sys. argv [2])
Search2 (a, m)
Run:
Administrator @ ubuntu :~ /Python $ python test_search2.py 123456789 4
3
Note:
1. '_': Because python class members are both public and publicly accessible and public, there is a lack of private attributes like the Orthodox object-oriented language.
So we will use _ to simulate private attributes. These _ attributes are often used internally and generally do not need to be rewritten. No need to read.
The purpose of adding two underscores (_) is not to conflict with the names of common public properties, or to prevent users (non-developers) of objects from using them at will.
2. _ name _ = "_ main _" indicates that the script is directly executed.
If not, the script is imported by another program using import.