List

  • What are lists?

    • Lists are used to store multiple items in a single variable.

    • Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.

    • Lists are created using square brackets:

Names = ["Ananya", "Ishi", "Ekam"]
print(Names)
['Ananya', 'Ishi', 'Ekam']

Dictionaries

  • What are dictionaries?

    • Dictionaries are used to store data values in key:value pairs.

    • A dictionary is a collection which is ordered*, changeable and do not allow duplicates.

    • Dictionaries are written with curly brackets, and have keys and values:

Info = {
  "Name": "Ananya",
  "Age": 15,
  "Grade": 10
}
print(Info)
{'Name': 'Ananya', 'Age': 15, 'Grade': 10}

Python Iterators

  • What are Iterators?

    • An iterator is an object that contains a countable number of values.

    • An iterator is an object that can be iterated upon, meaning that you can traverse through all the values.

    • Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods iter() and next().

Names = ["Ananya", "Ishi", "Ekam"]
myit = iter(Names)

print(next(myit))
print(next(myit))
print(next(myit))
Ananya
Ishi
Ekam