NEW
Font size
WorksheetsPYTHON BE PYTHONING
Total questions: 50
Worksheet time: 25mins
What is the correct file extension for Python files?
.pyth
.pt
.py
.python
Which of the following is a valid Python variable name?
2value
my-value
value_1
class
What does print(type("Hello")) output?
<class 'string'>
<string>
<class 'str'>
str
Which function is used to read input from a user?
input()
get()
read()
prompt()
Which tool can help with debugging Python code?
debug.start()
ipdb
pytrace
bugger
Which command runs a Python test using pytest?
python test.py
pytest test_file.py
run test.py
python3 -t test.py
What is the output of print(5 // 2)?
2.5
3
2.0
2
Which of the following keywords is used to define a function?
define
function
def
fun
What will print(x) do if x was never defined?
Print nothing
Throw a warning
Raise a NameError
Set x to None
What determines the scope of a variable in Python?
Its data type
Its indentation
Its casing
Its line number
What happens if you don't indent inside a function?
Nothing
Python ignores the code
SyntaxError
IndentationError
Which operator is used for exponentiation?
^
**
%
^^
Which statement is used for decision making in Python?
switch
case
if
check
Which loop repeats as long as a condition is true?
for
loop
repeat
while
Which keyword is used to define a decorator?
decorate
@
#
*
Which data structure is ordered and mutable?
Tuple
List
Set
Dictionary
What will [x*x for x in range(3)] return?
[1, 2, 3]
[0, 1, 4]
[1, 4, 9]
[0, 2, 6]
Which keyword is used to define a generator?
return
yield
generate
pass
How do you get all keys from a dictionary d?
d.values()
d.get_keys()
d.keys()
keys(d)
Which of the following structures ensures unique elements?
List
Dictionary
Set
Tuple
Which keyword is used to define a class?
function
method
class
defclass
What is self in a method definition?
A global variable
The class name
A reference to the instance
A built-in object
What does __init__ do?
Runs the class logic
Initializes the module
Initializes the object
Defines a method
Which decorator turns a method into a property?
@attr
@prop
@property
@getter
Which of the following is NOT a principle of OOP?
Encapsulation
Inheritance
Compilation
Polymorphism
Which keyword is used to inherit from another class?
inherits
extends
from
class BaseClass:
Which method refers to the superclass?
super()
parent()
base()
main()
Which function creates anonymous functions?
def
lambda
anon
func
How is a class attribute defined?
Inside a method
With @classmethod
Outside any method
With global
Which decorator is used for class methods?
@class
@staticmethod
@classmethod
@method
Which keyword is used to bring in a module?
require
import
include
fetch
Which file is used by pipenv to manage dependencies?
requirements.txt
setup.py
Pipfile
env.yaml
Which command installs a package using pip?
pip install
pip get
install pip
pipenv add
What is a typical Python script entry point?
start()
def script():
if __name__ == "__main__":
main.run()
Which relationship describes one object owning many others?
One-to-one
One-to-many
Many-to-many
Inheritance
Which of the following best describes a join table?
A table with indexes
A table linking many-to-many objects
A table with all data types
A system table
Which module is used for regular expressions in Python?
regex
regexp
re
express
What does \d match in regex?
A digit
A decimal
A dot
A date
Which command is used to create a table?
ADD TABLE
MAKE TABLE
CREATE TABLE
INSERT TABLE
Which command adds data to a SQL table?
INSERT INTO
ADD TO
UPDATE
PUT INTO
Which SQL data type stores text?
INT
VARCHAR
NUMERIC
FLOAT
What does a foreign key do?
Creates a duplicate table
Links two tables
Deletes rows
Filters rows
Which keyword joins tables in SQL?
JOIN
MERGE
APPEND
LINK
What does ORM stand for?
Object-Related Methods
Object-Relational Mapper
Object Runtime Model
Object Reference Module
Which decorator is used in SQLAlchemy to define a column?
@column
Column()
@Column
@field
Which function adds a record in SQLAlchemy?
db.add(obj)
obj.insert()
add.record()
save(obj)
What is a relationship() in SQLAlchemy?
A method to delete data
A function for seeding data
A function that links two models
A data type
Which relationship allows each item to have multiple related items?
One-to-one
One-to-many
Many-to-one
Singleton
What does CLI stand for?
Click Language Interface
Command Line Interface
Code Loop Interpreter
Control Logic Input
Which module helps build command-line apps in Python?
cli
terminal
click
command
