Writing Idiomatic Python 2.7.3 by Jeff Knupp

Writing Idiomatic Python 2.7.3 by Jeff Knupp

Author:Jeff Knupp [Knupp, Jeff]
Language: eng
Format: epub
Google: KbALbu0lBmYC
Publisher: Jeff Knupp
Published: 2013-02-06T21:24:09+00:00


5.5.3.2 Idiomatic

unique_surnames = set(employee_surnames) def display(elements, output_format='html'): if output_format == 'std_out': for element in elements: print(element) elif output_format == 'html': as_html = '<ul>' for element in elements: as_html += '<li>{}</li>'.format(element) return as_html + '</ul>' else: raise RuntimeError('Unknown format {}'.format(output_format))

5.6 Tuples

5.6.1 Use _ as a placeholder for data in a tuple that should be ignored

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.”



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.