for arg in argsoutput +('if first else sepstr(argfirst false file write(output endthis version works the same as the originaland it' prime example of how keywordonly arguments come in handy the original version assumes that all positional arguments are to be printedand all keywords are for options only that' almost sufficientbut any extra keyword arguments are silently ignored call like the followingfor instancewill generate an exception correctly with the keyword-only formprint ( name='bob'typeerrorprint (got an unexpected keyword argument 'namebut will silently ignore the name argument in the original version to detect superfluous keywords manuallywe could use dict pop(to delete fetched entriesand check if the dictionary is not empty the following versionin the file print _alt pyis equivalent to the keyword-only version--it triggers built-in exception with raise statementwhich works just as though python had done so (we'll study this in more detail in part vii)#!python "use / keyword args deletion with defaultsimport sys def print (*args**kargs)sep kargs pop('sep''end kargs pop('end''\ 'file kargs pop('file'sys stdoutif kargsraise typeerror('extra keywords%skargsoutput 'first true for arg in argsoutput +('if first else sepstr(argfirst false file write(output endthis works as beforebut it now catches extraneous keyword argumentstooprint ( name='bob'typeerrorextra keywords{'name''bob'this version of the function runs under python xbut it requires four more lines of code than the keyword-only version unfortunatelythe extra code is unavoidable in this case--the keyword-only version works on onlywhich negates most of the reason that wrote this example in the first placea emulator that only works on isn' incredibly usefulin programs written to run on onlythoughkeywordonly arguments can simplify specific category of functions that accept both arguments and options for another example of keyword-only argumentsbe sure to see the iteration timing case study in emulating the python print function