Revature Python Flashcards
What is the difference between a interpreter and a compiler?
Compilers execute the whole source code into machine readable code. A interpretor executes code line by line. Interpretors are generally slower due to having to process the code while executing.
What is Repl
It stands for read eval print loop. It is a interactive pyhton coding environment that allows one to execute code immediately Some good use cases of this would be for functional coding.
What is a compound statement?
A compound statement are groups of statements together. An example would be a if forloop block.
What is a namespace?
A namespace is a container that holds the name of (variables, functions, objects) and holds their values to avoid conflicting name titles.
What is a scope of a variable
The scope determines where the variable can be accessed. For example we cant access a variable that hasnt been instantiated yet.
What are some different operators in python?
There are arithmetic comparison logical assignment, membership and identity
What are functions?
They’re blocks of reusable code to perform task
What is a lambda function and how do you create one?
Lambda functions are one line function
syntax: lambda arguements: expression
example: square = lambda x: x**2
What is a tuple
A tuple is an immutable collection of elements
What is a module? How do we import it?
A module is a file containing python code. You can import it by using the import module_name. For best practices you don’t want to import the the entire module, but just what you need. For example from module _name import function_name
What is a datetime object?
a datetime object is a object used to collect or calculate the current date and time of the machine.
What is regular expression?
Regular expression (Regex) is a sequence of characters used for string matching and manipulations. It is especially useful for login credentials to ensure user input falls in line with the guidelines.
import re
result = re.match(r”\d+”, “123abc”)
Name some Collection Modules for data collection?
Counter: Counts occurrences of elements.
deque: Double-ended queue.
defaultdict: Dictionary with a default value.
namedtuple: Tuple with named fields.
OrderedDict: Maintains insertion order.
What is a class, whats is an object?
Classes are blue prints for objects. Objects are instances of a class.
What are exceptions?
Exceptions: A problem that occur during program execution disrupting the flow of the program. They are used to handle runtime errors
Handling: Use try, except, else, and finally.
Example:
python
Copy code
try:
result = 10 / 0
except ZeroDivisionError:
print(“Cannot divide by zero!”)