Types Of Functions Flashcards

1
Q

How to use range() function

A

for I in range(0,20,2)
Print(i)
Output= 2 4 6 8 10 12 14 16 18

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Python range(start, stop, step)

A

Start Stop
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 , 9, 10
Step (2)
Output 0 2 4 6 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are tuples?

A

Tuples are an ordered sequences of items, just like lists. The main difference between tuples and lists is that tuples cannot be changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are dictionaries?

A

Dictionaries are data structures that map unique keys to value, but dictionary keys can be any immutable data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to use dictionary values as a function

A

webstersDict[‘marathon’]

Output- a running race that is about 26 miles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to add new key-value pair to an existing dictionary

A

webstersDict[‘shoe’] = ‘an external covering for the human foot’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to update dictionary keys

A

webstersDict update({‘ran’ : ‘past tense of run’, ‘shoes’ : ‘plural of shoe’})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to use get() method

A

Story count = {‘is’ : 100,’the’ : 90, ‘michael’ : 12, ‘runs’ : 5}
storycount.get(‘Michael’)
Output- 12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

pop(method)

A

The pop method removes a key and returns the value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to use pop() method

A

storyCount.pop(‘the’)

Output- 90

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is keys() method

And how is it used?

A

The keys method returns the keys of the dictionary as a dictionary view object.
keys() type(storyCount.keys())
Output- dict_keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is values() method?

A

The values method returns the values in the dictionary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to use values() method?

A

storyCount.values()

Output- dict_values([100, 12, 5])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is items() method?

A

The items method returns a dictionary view object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to use items() method

A

list(webstersDict.items())
Output-[(‘person’,, ‘a human being’)]
Etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are loops?

A

A for loop is used for iterating over a sequence (list, tuple, dictionary, string, etc).

17
Q

How to use loops?

A

myName = “Michael”
for x in myName:
print(x)
Output- M i c h a e l

18
Q

How to use loops for index?

A

list(range(0,10))

Output- [0,1,2,3,4,5,6,7,8,9]

19
Q

What is enumerate function?

A

The enumerate function returns a tuple containing a count for every iteration (from start which defaults to 0)

20
Q

How to use enumerate?

A

DataScienceTools = [‘Python’, ‘R’, ‘SQL’, ‘Git’ ]
for index, tool in enumerate(dataScienceTools):
print(index,tool)
Output- 0 Python 1 R 2 SQL 3 Git

21
Q

How to convert strings to upper or lower case?

A

upper() method

lower() method

22
Q

What is a comment in python and how is it used?

A
#This is a comment
print("Hello, World!")