optparse has six built-in option types:string,int,long,choice,float andcomplex. If you need to add new optiontypes, see section 14.3.5, Extendingoptparse.
Arguments to string options are not checked or converted in any way: thetext on the command line is stored in the destination (or passed to thecallback) as-is.
Integer arguments (typeint orlong) are parsed as follows:
0x, it is parsed as a hexadecimal number0, it is parsed as an octal number0b, it is parsed as a binary numberThe conversion is done by calling eitherint() orlong() withthe appropriate base (2, 8, 10, or 16). If this fails, so willoptparse,although with a more useful error message.
float andcomplex option arguments are converted directly withfloat() andcomplex(), with similar error-handling.
choice options are a subtype ofstring options. Thechoicesoption attribute (a sequence of strings) defines the set of allowedoption arguments.optparse.check_choice() comparesuser-supplied option arguments against this master list and raisesOptionValueError if an invalid string is given.