Saturday, 11 August 2018

Is there a list of Python shorthand commands for making lists, dictionaries, etc?





I know about foo = [] being shorthand for foo = list() and I was wondering if there was a list of shorthand notations for creating empty dictionaries, tuples, sets, etc. I'm specifically looking for Python 3.x but either one would be useful to have.


Answer



To create an empty dictionary, use {}.
To create an empty tuple, use ().
There is no shortcut for an empty set.
As for the etc., I don't know what else you are thinking of.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...