Posts

Theory on Dictionary

  # Introduction It is an unordered collection of items where each item consists of a key and a value. It is mutable (can modify its contents) but Key must be unique and immutable.   Creating Dictionary It is enclosed in curly braces { } and each item is separated from other item by a comma (,).Within each item, key and value are separated by a colon(:). dictonary_name={key:value, key: value, ……..keyN:valueN}   Example : day= {1: 'Monday', 2:'Tuesday', 3: 'Wednesday'} print day Output: {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday'}   # Accessing Dictionary Item day= {1: 'Monday', 2:'Tuesday', 3: 'Wednesday'} print day print day[1] print day[3]   Output: {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday'} Monday Wednesday   In above code we are accessing dictionary using key. day= {1: 'Monday', 2:'Tuesday', 3: 'Wednesday'} print(day.get(1)) Output : Monday #  Iterating Through A ...

Working with Lists

  # Introduction A list is a data type that can be used to store any type and number of variables and information. The values in the list are called elements or items or list members. A list in Python is formed by enclosing the values inside square brackets []. Unlike strings, lists are mutable, i.e., values in a list can be changed or modified and can be accessed using index value enclosed in square brackets. Lists are not suitable for every task. There are other data types like arrays, tuples and dictionaries which may be more suitable for certain tasks. First scope out problem and then decided which data type fits the best. # Python Lists Syntax  mylist = ["C","C++","Java","Python","PHP"] The items within the list must be enclosed within square brackets, and each item must be separated by a comma. Unlike arrays, Lists can store any type of data type as well as store variables of different datatypes at the same time. The double quotes...