Introduction to Programming with Python Flashcards
List three reasons why Python is a popular language among educators and learners.
Python is free, and a variety of supporting tools, modules, and libraries are available at no cost to aspiring developers.
Python’s syntax is concise compared to that of many other languages, which means you can do more with less, reducing the demand on the programmer.
Python code is also easier to read than code written in many other languages because one of the central concepts in the creation of Python was that the code should resemble everyday English.
Python has a very active developer community that creates resources for entry-level and expert Python developers.
List three reasons why Python is a popular language among professionals.
Despite being relatively easy to use and read, Python is extremely robust and powerful.
Because Python is so easy to use and such a concise language, it is a popular choice for quickly building working prototypes.
Python is the language of choice for data science and is heavily used in artificial intelligence.
Python is already extremely popular among educators, learners, and practitioners, and the trends show that this momentum is only increasing. That means more jobs with higher salaries are available to Python developers. Learning Python can help you pay the bills!
What is the Python interpreter?
A program that reads Python code, translates it into something called byte code, and then executes the code in a Python Virtual machine, returning the output to the user
Which of the following is a difference between interpreted languages and compiled languages? (select all that apply).
Compiled languages are processed into machine code and stored as separate executables for users to run.
Interpreted languages are parsed and executed without storing a separate machine code executable.
What is the relationship of Jupyter to IPython?
Jupyter evolved from IPython.
What is JupyterLab?
An integrated development environment that allows developers to organize and develop in multiple documents with code, Markdown, and text alongside terminals and other components.
NumPy:
An extremely efficient library used for the computation of large data sets and multi-dimensional arrays.
SciPy:
A library used for scientific computing including linear algebra, interpolation, and signal and image processing.
Pandas:
A library used for data manipulation in numerical tables and time series data.
What is Anaconda?
Anaconda is a distribution that includes Python and various other tools including SciPy, NumPy, and pandas.
When the interpreter gives you an error of “invalid syntax,” what is the most likely cause?
I tried to use a variable name that is not valid.
What type of value is 0o42?
octal
What type of value is 42?
int
What type of value is 4 + 2J?
complex
What type of value is 4.2?
float
What is the result of this equation: int(5.8 * 2)?
11
How would you put quotation marks into a string in Python?
my_string = “this has "quotes".”
How do you get the length of a string in Python?
len(my_string)
If there is a string “my_string” with the value “I love Python!” how do you substring to get just “Python!”?
my_string[7:]
If there is a string “my_string” with the value “I love Python!,” how do you substring to get just “love”?
my_string[2:6]
What is the purpose of an escape character?
To include special characters in a string like a backslash or quotation mark
What is the purpose of a collection in Python?
to simplify code
to let the programmer combine multiple pieces of data into one variable object
to allow you to organize data more effectively
What is a key difference between a dictionary and a set?
Dictionaries store elements in key/value pairs, and sets do not.
What is the proper way to add the number 24 as an element to the set that I’ve named “my_favorite_numbers”?
my_favorite_numbers.add(24)
What is the proper way to add the number 24 at index 3 of the list that I’ve named “my_favorite_numbers”?
my_favorite_numbers.insert(3, 24)
What is the command to open a file in Python?
open
What does “x” do when used with the file open method?
Creates a new file with the specified file name; if it already exists, you will get an error message
What does “r” do when used with the file open method?
opens the file in read mode
What is the fastest way to initialize four variables (a, b, c, and d) all equal to 5?
a = b = c = d = 5
Which of the following lines of code will print the output of all four variables (a, b, c, and d)?
print(a, b, c, d)
I have a variable called my_int that holds the integer value 42. I want to convert that value to a string data type and assign that value to a variable called my_str. Which of the following will do that?
my_str = str(my_int)
What is the difference between an expression and a statement in Python?
A statement is a line of code the interpreter can execute, an expression is a section of code that the interpreter evaluates to a value.
What is a StopIteration exception in Python?
An error code received from the interpreter when moving past the end of a list
I have a list called “my_numbers” that contains the values 4, 8, 15, 16, 23, and 42. I want to loop through that list using an iterator. Each time through the list, I want the variable “next_value” to contain the next value in the list. Which of the following lines of code will do that?
for next_value in my_numbers:
I have a list called “my_list” that contains four values (1, 2, 3, and 4). I created an iterator for my_list called “my_iterator.” What happens when I call next(my_iterator) five times in a row?
The values 1, 2, 3, and 4 will be printed, and then a StopIterator error will be shown.
I have a list called “my_list” that contains four values (1, 2, 3, and 4). I want to create a new list called “my_new_list” from my existing list “my_list.” I want my_new_list to contain only the even values from my_list, and I want each of those values to be multiplied by 100. Which of the following will accomplish that using a list comprehension?
my_new_list = [n*100 for n in my_list if n% 2 == 0]
What is scope?
Scope is the sections within code for which a variable or function is defined.