Editing Python data types cheat sheet
From CommunityData
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 14: | Line 14: | ||
>>> 4 / 2 | >>> 4 / 2 | ||
2 | 2 | ||
>>> 1 / 2 | >>> 1 / 2 | ||
0 | |||
* Integer division produces an integer. You need a number that knows about the decimal point to get a decimal out of division: | |||
>>> 1.0 / 2 | |||
0.5 | |||
>>> float(1) / 2 | |||
0.5 | 0.5 | ||
====Types==== | ====Types==== | ||
Line 238: | Line 243: | ||
File "<stdin>", line 1, in <module> | File "<stdin>", line 1, in <module> | ||
KeyError: 'Eve' | KeyError: 'Eve' | ||
>>> "Eve" in | >>> "Eve" in her_dict | ||
False | False | ||
>>> "Alice" in | >>> "Alice" in her_dict | ||
True | True | ||
>>> your_dict.get("Eve") | >>> your_dict.get("Eve") | ||
Line 261: | Line 266: | ||
>>> type(my_dict) | >>> type(my_dict) | ||
<type 'dict'> | <type 'dict'> | ||