Python Flashcards
What is a generator in Python?
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.
What are Lambda functions in Python?
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.
What’s a dynamically typed language?
Type checking happens during execution instead of prior like in a statically-typed language
What’s an interpreted language?
An interpreted language isn’t compiled and instead is evaluated line-by-line by a program called an interpreter
What’s the difference between lists and tuples?
Lists and tuples both store a collection of objects. Tuples are immutable.
What’s a set?
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.
What is pass in python?
Pass is a null operation that is commonly used to fill empty blocks of code that haven’t been written
What is yield in python?
Yield is used with generators. It pauses execution of a generator function until gen.__next__() is called again.
What are the difference between arrays and lists in python?
Arrays can only have a single datatype whereas lists can combine multiple
How is memory managed in python?
Python has a Memory Manager that allocates a private heap space for python. It is not accessible to the programmer.
What is scope resolution in Python?
Python draws a line between namespaces and it
What are decorators in python?
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 do you deep copy an object in python?
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.
What’s the difference between shallow and deep copying
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.
Is Python pass-by-value or pass-by-reference
Neither, or both. Immutable objects are pass-by-value, mutable ones are pass-by-reference