Writing Idiomatic Python 3 by Jeff Knupp

Writing Idiomatic Python 3 by Jeff Knupp

Author:Jeff Knupp [Knupp, Jeff]
Language: eng
Format: epub
Publisher: Jeff Knupp
Published: 2013-11-30T04:30:00+00:00


When setting a tuple equal to some ordered data, oftentimes not all of the data is actually needed. Instead of creating throwaway variables with confusing names, use the _ as a placeholder to tell the reader, “This data will be discarded.”

6.6.2.1 Harmful

(name, age, temp, temp2) = get_user_info(user) if age > 21: output = '{name} can drink!'.format(name=name) # "Wait, where are temp and temp2 being used?"

6.6.2.2 Idiomatic

(name, age, _, _) = get_user_info(user) if age > 21: output = '{name} can drink!'.format(name=name) # "Clearly, only name and age are interesting"



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.