Types Of Functions Flashcards
How to use range() function
for I in range(0,20,2)
Print(i)
Output= 2 4 6 8 10 12 14 16 18
Python range(start, stop, step)
Start Stop
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 , 9, 10
Step (2)
Output 0 2 4 6 8
What are tuples?
Tuples are an ordered sequences of items, just like lists. The main difference between tuples and lists is that tuples cannot be changed.
What are dictionaries?
Dictionaries are data structures that map unique keys to value, but dictionary keys can be any immutable data type
How to use dictionary values as a function
webstersDict[‘marathon’]
Output- a running race that is about 26 miles
How to add new key-value pair to an existing dictionary
webstersDict[‘shoe’] = ‘an external covering for the human foot’
How to update dictionary keys
webstersDict update({‘ran’ : ‘past tense of run’, ‘shoes’ : ‘plural of shoe’})
How to use get() method
Story count = {‘is’ : 100,’the’ : 90, ‘michael’ : 12, ‘runs’ : 5}
storycount.get(‘Michael’)
Output- 12
pop(method)
The pop method removes a key and returns the value
How to use pop() method
storyCount.pop(‘the’)
Output- 90
What is keys() method
And how is it used?
The keys method returns the keys of the dictionary as a dictionary view object.
keys() type(storyCount.keys())
Output- dict_keys
What is values() method?
The values method returns the values in the dictionary
How to use values() method?
storyCount.values()
Output- dict_values([100, 12, 5])
What is items() method?
The items method returns a dictionary view object
How to use items() method
list(webstersDict.items())
Output-[(‘person’,, ‘a human being’)]
Etc.