Welcome to CCP,
so, we left off on dictionaries,
what are dictionaries in python3,
Note: whenever I say "Dictionary", I will be referring to the ones in python,
lets start,
dictionaries are a data structure similar usage to the lists,
they are defined b/w {} and not () and [],
like this:
we can find here that it is of type "dict" and can be used in if statements to compare different data types,
like this:
now,
lets define a dictionary with some elements in it,
like this:
here,
the words to the left of ":" are called keys which are used to access the the numbers on the right of ":" are called values,
lets take another example:
now it should be clear that we call values/elements in list with their indexes and in dictionaries, there are no indexes but there are keys which can be used to get values corresponding to them,
now,
iterating through dictionaries:
we can iterate through dictionaries via for loop over their keys to get values corresponding to them,
like this:
notice the comma in print() function,
it is used to print 2 values separated by a space,
it is a way of formatting strings (most basic one),
and now you can create your own dictionary,
is it better than oxford's ?
hah,
see you later with a new data structure similar to these but different as they can't be edited,
sounds weird huh ?
see me in the next tutorial !
Comments
Post a Comment