Posts Tagged ‘Dictionary’

Add new keys to dictionary in Python

We can add an item to existing dictionary in Python using following methods. Method1: Using update method of dictionary: 1. Create dictionary: >>> countries={‘United States of America’:’Washington’,’Canada’:’Ottawa’,’India’:’New Delhi’} >>> countries {‘United States of America’: ‘Washington’, ‘Canada’: ‘Ottawa’, ‘India’: ‘New Delhi’}

Difference between Lists and Tuples in Python

List Tuple List objects are mutable objects. Which means can be changed after its created Tuple objects are immutable objects. Which means can’t be changed after its created Lists have order Tuple has structure Iterating the list is slower Iterating the tuple is faster List objects are not used as keys for the dictionary Tuple […]

Powered by k2schools