Python Glossary Flashcards

1
Q

What is a Class in Python?

A

Python has classes which are defined wireframes of objects. Python supports class inheritance. A class may have subclasses but may only inherit directly from one superclass.

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

What are comments?

A

Augmenting code with human readable descriptions can help document design decisions.

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

What are dictionaries?

A

Dictionaries are Python’s built-in associative data type. A dictionary is made of key-value pairs where each key corresponds to a value. Like sets, dictionaries are unordered. A single dictionary can contain keys of varying types and values of varying types.

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

What are functions?

A

Python functions can be used to abstract pieces of code to use elsewhere.

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

What are function objects?

A

Python functions are first-class objects, which means that they can be stored in variables and lists and can even be returned by other functions.

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

What does the len() function do?

A

Using len(some_object) returns the number of top-level items contained in the object being queried.

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

What is a list comprehension?

A

Convenient ways to generate or extract information from lists

EXAMPLE:
» x_list = [1,2,3,4,5,6,7]
» even_list = [num for num in x_list if (num % 2 == 0)]
» even_list
[2,4,6]

> > m_list = [‘AB’, ‘AC’, ‘DA’, ‘FG’, ‘LB’]
A_list = [duo for duo in m_list if (‘A’ in duo)]
A_list
[‘AB’, ‘AC’, ‘DA’]

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

What are lists?

A

A Python data type that holds an ordered collection of values, which can be of any type. Lists of Python’s ordered mutable data type. Unlike tuples, lists can be modified in-place.

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

What are the types of loops in Python?

A
  • For loops - provide a clean iteration syntax
  • While loops - permits code to execute repeatedly until a certain condition is met. This is useful if the number of iterations required to complete a task is unknown prior to flow entering the loop.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the range() function do?

A

The range() function returns a list of integers, the sequence of which is defined by the arguments passed to it.

EXAMPLE:
» range(4)
[0, 1, 2, 3]

> > range(2, 8)
[2, 3, 4, 5, 6, 7]

> > range(2, 13, 3)
[2, 5, 8, 11]

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

What are sets in Python?

A

Sets are collections of unique but unordered items. It is possible to convert certain iterables to a set.

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

What is a slice?

A

A Pythonic way of extracting “slices” of a list using a special bracket notation that specifies the start and end of the section of the list you wish to extract. Leaving the beginning value blank indicates you wish to start at the beginning of the list, leaving the ending value blank indicates you wish to go to the end of the list. Using a negative value references the end of the list (so that in a list of 4 elements, -1 means the 4th element). Slicing always yields another list, even when extracting a single value.

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

What does the function str() do?

A

Using the str() function allows you to represent the content of a variable as a string, provided that the data type of the variable provides a neat way to do so. It does not change the variable in place, it returns a “stringified” version of it. It calls the special __str__ method of the object passed to it.

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

What are String?

A

Strings store characters and have many built-in convenience methods that let you modify their content. Strings are immutable, meaning they cannot be changed in place.

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

What are tuples?

A

A Python data type that holds an ordered collection of values, which can be of any type. They are immutable, meaning they cannot be changed once created.

EXAMPLE:
» x = (1, 2, 3, 4)
» y = (‘spam’, ‘eggs’)

> > my_list = [1,2,3,4]
my_tuple = tuple(my_list)
my_tuple
(1, 2, 3, 4)

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

What is tuple assignment?

A

Tuples can be expanded into variables easily.

EXAMPLE:
name, age = (“Alice”, 19)
# Now name has the value “Alice” and age has the value 19

You can also omit the parentheses:
name, age = “Alice”, 19

17
Q

What are variables?

A

Variables are assigned values using the == operator, which is not to be confused with the == sign used for testing equality. A variable can hold almost any type of value such as lists, dictionaries, functions.