Python Flashcards

1
Q

What is a generator in Python?

A

Generators are functions that return an iterable collection of items one at a time in a set manner. They use yield instead of return to return a generator object. To create a generator you make a function that yields instead of returns. When a generator is called, it doesn’t execute the function body immediately, instead it returns a generator object. To call the next iteration call x.__next__(). The generator function is paused after the yield line until the next iteration is called.

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

What are Lambda functions in Python?

A

A lambda function is an anonymous function that can accept many arguments but only execute a single expression. They’re typically used in situations where the function only needs to be short-lived.

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

What’s a dynamically typed language?

A

Type checking happens during execution instead of prior like in a statically-typed language

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

What’s an interpreted language?

A

An interpreted language isn’t compiled and instead is evaluated line-by-line by a program called an interpreter

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

What’s the difference between lists and tuples?

A

Lists and tuples both store a collection of objects. Tuples are immutable.

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

What’s a set?

A

A set is unordered and unindexed. You can’t change a sets items, but you can remove and add them. Also duplicates are not allowed.

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

What is pass in python?

A

Pass is a null operation that is commonly used to fill empty blocks of code that haven’t been written

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

What is yield in python?

A

Yield is used with generators. It pauses execution of a generator function until gen.__next__() is called again.

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

What are the difference between arrays and lists in python?

A

Arrays can only have a single datatype whereas lists can combine multiple

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

How is memory managed in python?

A

Python has a Memory Manager that allocates a private heap space for python. It is not accessible to the programmer.

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

What is scope resolution in Python?

A

Python draws a line between namespaces and it

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

What are decorators in python?

A

they are essentially “wrapper” functions that add functionality to another function without modifying the function’s code. They are indicated with @decorator_name above the function definition.

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

How do you deep copy an object in python?

A

The assignment operator creates a binding between a target and an object, e.g. the target is a reference to the original. To copy an object you must use the copy module. It allows both shallow and deep copying.

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

What’s the difference between shallow and deep copying

A

Shallow copying creates a new object but makes references of any objects found inside. Deep copying creates a new object and new inside objects too.

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

Is Python pass-by-value or pass-by-reference

A

Neither, or both. Immutable objects are pass-by-value, mutable ones are pass-by-reference

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

What are static variables in Python

A

Static or class variables are shared amongst all instances of a class