def lessthan(xy)return def grtrthan(xy)return if __name__ ='__main__'print(minmax(lessthan )print(minmax(grtrthan )self-test code we're also printing the value of __name__ at the top here to trace its value python creates and assigns this usage-mode variable as soon as it starts loading file when we run this file as top-level scriptits name is set to __main__so its self-test code kicks in automaticallyc:\codepython minmax py am__main__ if we import the filethoughits name is not __main__so we must explicitly call the function to make it runc:\codepython import minmax amminmax minmax minmax(minmax lessthan' '' '' '' ''aagainregardless of whether this is used for testingthe net effect is that we get to use our code in two different roles--as library module of toolsor as an executable program per ' discussion of package relative importsthis section' technique can also have some implications for imports run by files that are also used as package components in xbut can still be leveraged with absolute package path imports and other techniques see the prior discussion and example for more details exampledual mode code here' more substantial module example that demonstrates another way that the prior section' __name__ trick is commonly employed the following moduleformats pydefines string formatting utilities for importersbut also checks its name to see if it is being run as top-level scriptif soit tests and uses arguments listed on the system command line to run canned or passed-in test in pythonthe sys argv list contains command-line arguments--it is list of strings reflecting words typed on the command linewhere the first item is always the name of the script being run we used this in ' benchmark tool as switchesbut leverage it as general input mechanism here#!python ""exampledual mode code