ALL THE TEST Flashcards

1
Q

How can a program written in a high-level programming language be executed?

A

By rendering it into machine language

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

What happens if the interpreter detects an error in the code?

A

It finishes its work immediately and displays an error message

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

Machine languages are devloped by computers.

A

False

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

Interpreters read and execute source code from bottom to top and right to left.

A

False

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

Select the true statements. (Select two answers)

A

Python 3 is not backwards compatible with Python 2

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

What do you call a command-line interpreter which lets you interact with your OS and execute Python commands and scripts?

A

A console

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

What is the execution model of an interpreted language?

A

Read, check, execute (repeated for each line)

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

Why is Python named after Monty Python?

A

The name of the Python programming language comes from an old BBC television comedy sketch series called Monty Python’s Flying Circus.

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

Where is Python extensively used?

A

Python is used to implement complex Internet services, everyday-use applications, and scientific research.

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

What are the two main versions of Python?

A

The two main versions of Python are Python 2 and Python 3. Python 2 is older and Python 3 is the current version.

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

Python is primarily used for low-level programming.

A

False

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

What do high-level programming languages enable humans to do?

A

Express complex commands to computers

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

Is Python suitable for low-level programming or mobile applications?

A

Python is not suitable for low-level programming or mobile applications.

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

What is CPython?

A

It’s the default, reference implementation of Python, written in the C language

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

What language does a computer CPU process and understand?

A

Machine language

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

Based on this class, what makes a computer usable?

A

A program

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

What is the historical term for languages designed to be interpreted?

A

Scripting languages

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

What is a high-level programming language?

A

A language readable by humans and capable of complex commands

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

Language is a means of expressing and recording thoughts.

A

True

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

What is CPython?

A

CPython is the traditional implementation of Python, often referred to as just “Python”.
(This is the end of the 1st quiz)

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

The * operator can be used to replicate strings.

A

True

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

The input() function is used to send data to the console.

A

False

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

The input() function is used to get user input from the console.

A

True

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

What is the meaning of the hierarchy of priorities in Python?

A

Determines the order of operations performed by operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
What is the output of the following snippet? z = y = x = 1 print(x, y, z, sep='*')
1*1*1
21
What allows a program to read data entered by the user and return the same data to the program?
input()
22
How do you create single-line comments in Python?
By using the # symbol at the beginning of the line
23
Which operator is used for concatenating strings?
+
24
What characters are allowed in a variable name?
Letters, digits, and underscore
25
Which function converts a string into an integer?
int()
26
The input() function can take a prompt message as an optional parameter.
True
27
How can you leave comments in Python code?
By using the # symbol at the beginning of a line
28
The int() function can be used to convert a string into a number.
True
29
The * operator can be used to multiply strings.
False
30
What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) x = x / y y = y / x print(y)
2.0
31
Variables in Python must be declared before they can be used.
False
32
How are variables created in Python?
By assigning a value to a variable
33
What are the basic data types in Python?
Integers, floats, strings, and booleans
34
What is the purpose of the int() function?
To convert a string into an integer
35
Which function converts a number into a string?
str()
36
The <= operator is used to check if one value is less than or equal to another.
True
37
What is the output of the following snippet? my_list = [1, 2, 3] for v in range(len(my_list)): my_list.insert(1, my_list[v]) print(my_list)
[1, 1, 1, 1, 2, 3]
38
Which function can be used to check the length of a list?
len()
39
What term is used, by analogy to algebraic terms, to describe a two-dimensional list?
Matrix
40
The == operator is used to check if two values are equal.
True
41
What happens when you assign one list to another list using the assignment operator?
Both variables point to the same memory location
42
What Python operator is used to ask if two values are not equal?
!=
43
How many hashes (#) will the following snippet send to the console? var = 1 while var < 10: print("#") var = var << 1
four
44
How many stars (*) will the following snippet send to the console? i = 0 while i <= 5 : i += 1 if i % 2 == 0: break print("*")
one
45
Which of the following sentences are true? (Select two answers) nums = [1, 2, 3] vals = nums[-1:-2]
nums is longer than vals nums and vals are two different lists
46
How many passes are needed to sort the entire list using the algorithm?
Depends on the list
47
How many hashes (#) will the following snippet send to the console? for i in range(1): print("#") else: print("#")
two
48
What is the output of the following snippet? my_list = [[0, 1, 2, 3] for i in range(2)] print(my_list[2][0])
the snippet will cause a runtime error
49
Which operator is used for greater than comparison?
>
50
The name of a list is the name of a memory location where the list is stored.
True
51
Which method can be used to add a new element to the end of a list?
append()
52
How many elements does the my_list list contain? my_list = [i for i in range(-1, 2)]
three
53
The > operator is used to check if one value is less than another.
False
54
What function can be used to get the number of elements in a list?
len()
55
The following snippet: def func(a, b): return a ** a print(func(2))
is erroneous
56
A tuple is an example of an immutable sequence type in Python.
True
57
What is a dictionary in Python?
An unordered collection of key-value pairs
58
What is a dictionary in Python?
An unordered, changeable, and indexed collection of key-value pairs
59
Which of the following lines properly starts a function using two parameters, both with zeroed default values?
def fun(a=0, b=0):
59
What is positional parameter passing in Python?
Passing arguments to a function based on their order
60
What is the output of the following code? tup = (1, 2, 4, 8) tup = tup[1:-1] tup = tup[0] print(tup)
2
61
What is the output of the following snippet? def f(x): if x == 0: return 0 return x + f(x - 1) print(f(3))
6
62
The following snippet: def func_1(a): return a ** a def func_2(a): return func_1(a) * func_1(a) print(func_2(2))
will output 16
63
What is recursion in the context of computer programming?
A technique where a function invokes itself
63
Which of the following is an example of a sequence type in Python?
List
64
The global keyword in Python can extend a variable's scope in a way that includes the function's body.
TRUE
65
A tuple can be created with parentheses or with a set of values separated by commas.
True
66
What is the scope of a variable in Python?
The part of the code where the variable is accessible.
67
What is the key characteristic of a tuple in Python?
Immutability - cannot be modified in situ
68
What are parameters in Python functions?
Variables that exist only inside the function and are provided by the invoker
69
What is the output of the following snippet? def fun(x, y, z): return x + 2 * y + 3 * z print(fun(0, z=1, y=3))
9
70
What is a dictionary in Python?
A mutable data structure that stores key-value pairs
70
A built-in function is a function which:
comes with Python, and is an integral part of Python
71
Functions are a reusable block of code that performs a specific task when invoked.
True
72
Is Python suitable for low-level programming or mobile applications?
Python is not suitable for low-level programming or mobile applications.
73
How do you create single-line comments in Python?
By using the # symbol at the beginning of the line
74
What is true about compilation?
It tends to be faster than interpretation
75
What is the execution model of an interpreted language?
Read, check, execute (repeated for each line)
76
What is the purpose of the print() function?
To send data to the console
76
What are reserved keywords in Python?
Words that have predefined meanings and cannot be used as variable names
77
How can you create a comment in your Python code?
By starting a line with a # sign
78
Which execution model does Python use?
Interpreting
79
Python is primarily used for low-level programming.
False
80
How can you concatenate two strings in Python?
By using the + operator
81
What is machine language?
The rudimentary language understood by computers
82
What does the * (asterisk) sign do when applied to a string and a number?
Replicates the string a number of times
82
How are variables created in Python?
By assigning a value to a variable
83
Which type of language is Python?
Scripting language
84
Are Python 2 and Python 3 compatible?
No, Python 2 and Python 3 are not compatible with each other.
85
What are some reasons to use Python?
It allows for faster development, easier understanding of code, and is free, open-source, and multiplatform.
86
The ** operator:
performs exponentiation
87
Why is Python named after Monty Python?
The name of the Python programming language comes from an old BBC television comedy sketch series called Monty Python's Flying Circus.
88
What are some features of Python?
Python is easy to learn and teach, easy to use, easy to understand, and easy to obtain, install, and deploy.
89
What is the expected behavior of the following program? print("Hello!")
The program will output Hello! to the screen
89
Python is a compiled programming language.
False
90
What language does a computer CPU process and understand?
Machine language
91
What is the purpose of the input() function?
To get data from the user
92
The input() function is used to send data to the console.
False
93
The input() function is used to get user input from the console.
True
94
Language is a means of expressing and recording thoughts.
True
95
What type of data can be stored in a variable in Python?
Any type of data
96
Which operator is used for concatenating strings?
+
97
The \n digraph forces the print() function to:
break the output line
98
What is the purpose of comments in Python code?
To provide explanations or additional information for human readers of the code, as they are ignored by Python at runtime.
99
Variables in Python must be declared before they can be used.
False
100
How can you leave comments in Python code?
By using the # symbol at the beginning of a line
101
What is the result of the concatenation operator (+) when applied to two strings?
The two strings are combined into one string.
102
The str() function can be used to convert a number to a string.
True
103
The print() function can concatenate strings using the + operator.
True
104
Computer programming involves composing elements of a programming language.
True
105
The * operator can be used to replicate strings.
True
106
What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = input() y = input() print(x + y)
24
107
What is the purpose of the int() function?
To convert a string into an integer
108
In the context of this class, what is Python?
Python is a widely-used, interpreted, object-oriented, and high-level programming language used for general-purpose programming.
109
A function's parameter can have the same name as a variable outside the function.
True
109
Which operator checks if a given value is stored inside a list?
in
110
The in operator in Python checks if an element is present inside a list.
True
110
What Python operator is used for bitwise conjunction?
&
111
What is the scope of a variable in Python?
The part of the code where the variable is accessible.
112
What Python operator is used to ask if one value is less than or equal to another?
<=
112
How many stars (*) will the following snippet send to the console? i = 0 while i <= 5 : i += 1 if i % 2 == 0: break print("*")
one
113
Which operator is used for less than comparison?
<
114
Tuples in Python are mutable, allowing elements to be added, modified, or removed.
False
115
What are the two fundamental types of functions in Python?
Built-in functions and user-defined functions
116
Which data type in Python is immutable?
Tuple
116
Changing the value of a function's parameter propagates outside the function.
False
117
What Python operator is used to ask if two values are not equal?
!=
117
What is a sequence type in Python?
A type of data that can store more than one value and can be iterated over using a for loop
118
The else statement is optional and is executed if all of the previous conditions are true.
False
118
The global keyword in Python can extend a variable's scope in a way that includes the function's body.
True
119
Which technique assigns arguments to function parameters based on their position?
Positional parameter passing
120
Which operator is used for less than or equal to comparison?
<=
120
What is the output of the following snippet? my_list = [[0, 1, 2, 3] for i in range(2)] print(my_list[2][0])
the snippet will cause a runtime error
121
What is the syntax for defining a function in Python?
def function_name(): function_body
121
How many elements does the my_list list contain? my_list = [i for i in range(-1, 2)]
three
122
What is the output of the following code? try: value = input("Enter a value: ") print(value/value) except ValueError: print("Bad input...") except ZeroDivisionError: print("Very bad input...") except TypeError: print("Very very bad input...") except: print("Booo!")
Very very bad input...
122
Which operator is used for greater than comparison?
>
123
The only place where a parameter can be defined is between a pair of parentheses in the def statement.
True
123
What does the 'in' operator do in relation to a list?
Checks if a given element is stored inside the list
124
The end index in a slice represents the index of the first element not included in the slice.
True
124
What is the output of the following snippet? my_list_1 = [1, 2, 3] my_list_2 = [] for v in my_list_1: my_list_2.insert(0, v) print(my_list_2)
[3, 2, 1]
125
Immutable data can be freely updated at any time during program execution.
False
126
Functions are a reusable block of code that performs a specific task when invoked.
True
127
Functions can have default values for certain parameters, which are used when the corresponding arguments are omitted.
True
128
A built-in function is a function which:
comes with Python, and is an integral part of Python
129
Which function can be used to check the length of a list?
len()
130
What is the result of the comparison operator == if the values are equal?
True
131
What is the output of the following snippet? my_list = [3, 1, -2] print(my_list[my_list[-1]])
1
132
What is a dictionary in Python?
An unordered, changeable, and indexed collection of key-value pairs
133
Which one of the following lines properly starts a parameterless function definition?
def fun():
134
Which of the following lines properly starts a function using two parameters, both with zeroed default values?
def fun(a=0, b=0):
135
When should you consider writing your own function?
When a particular piece of code begins to appear in more than one place
136
What is a parameter in Python?
A variable that is used to pass data to a function.
136
The elif statement is used to only one condition and executes a single block of code based on the first condition that is false.
Flase
137
What is a module in Python?
A file containing Python definitions and statements that can be imported and used when necessary
138
What is aliasing in Python?
Assigning a different name to an imported module or entity
138
Which command can you use pip to remove an installed package?
pip uninstall package
139
What does pip stand for?
pip installs packages
140
What does the random() function in the random module do?
Produces a float number from the range (0.0, 1.0)
141
Why is code maintenance easier with smaller code?
Searching for bugs is always easier when the code is smaller
142
Modules are used to divide a piece of software into separate but cooperating parts.
True
143
The math module in Python contains functions for logarithm and exponentiation operations.
True
144
What is the function of the sin(x) in math module?
To calculate the sine of x
145
Where can you find a directory of modules available in the Python universe?
Python Module Index
146
The following statement causes the import of _____. from a.b import c
entity c from module b from package a
147
A predefined Python variable that stores the current module name is called _____.
__name__
148
What is true about updating already installed Python packages?
It's performed by the install command accompanied by the -U option.
149
What is true about the pip install command?
It installs a package per user only when the --user option is specified.
150
Knowing that a function named fun() resides in a module named mod, choose the correct way to import it.
from mod import fun
151
Which statement is true about the pip search command?
It searches through all PyPI packages.
152
What is the purpose of the dir() function in Python?
To reveal all the names provided through a particular module
153
What is the expected output of the following code? from random import randint for i in range(2): print(randint(1, 2), end='')
11, 12, 21, or 22
154
Python is a leader in research on artificial intelligence.
True
155
Python code cannot be freely exchanged within the Python community.
False
156
What is decomposition in software development?
The process of dividing a piece of software into separate but cooperating parts
157
What is the purpose of the __name__ variable in Python?
To indicate if the file is run stand-alone or imported as a module
158
What is true about the pip install command?
It installs a package per user only when the --user option is specified.
159
The math module in Python provides functions for trigonometry operations like sine, cosine, and tangent.
True
159
What is the expected output of the following code? from random import randint for i in range(2): print(randint(1, 2), end='')
11, 12, 21, or 22
160
It is generally a good idea to mix functions with different application areas within one module.
False
161
What is the purpose of a package in Python?
To couple together related modules under one common name
162
The __pycache__ directory is automatically created when a module is imported for the first time.
True
163
What is true about updating already installed Python packages?
It's performed by the install command accompanied by the -U option.
164
What does the '*' symbol represent when importing a module in Python?
It imports all entities from the specified module
165
Where can you find a directory of modules available in the Python universe?
Python Module Index
166
The random module in Python generates truly random numbers.
False
167
What is the purpose of the random module in Python?
To operate with pseudorandom numbers
167
When a module is imported, its contents _____.
are executed once (implicitly)
168
What is a module in Python?
A file containing Python definitions and statements that can be imported and used when necessary
169
What is aliasing in Python?
Assigning a different name to an imported module or entity
170
The digraph written as #! is used to _____.
tell a Unix or Unix-like OS how to execute the contents of a Python file
171
A list of package dependencies can be obtained from pip using a command named _____.
show
172
When importing a module, you can give it an alias using the 'with' keyword.
False
172
During the first import of a module, Python deploys the pyc files in the directory called _____.
__pycache__
173
How can you safely check if an object contains a specific property in Python?
By using the hasattr() function
174
What concept in object programming allows a class to inherit traits from another class?
Inheritance
175
What is Method Resolution Order (MRO) in Python?
A strategy in which Python scans through the upper part of a class's hierarchy to find the method it needs
176
Python's __str__() method returns a string that is useful and informative by default.
False
176
What is the purpose of the self parameter in Python methods?
To identify the object for which the method is invoked
177
What will be the output of the following code? class A: X = 0 def __init__(self,v = 0): self.Y = v A.X += v a = A() b = A(1) c = A(2) print(c.X)
3
178
What is inheritance in object programming?
A practice of passing attributes and methods from a superclass to a subclass
179
The is operator checks if two variables refer to the same object in memory.
True
180
What does the is operator in Python do?
Check if two variables refer to the same object
181
What are instance variables in Python?
Properties that are specific to each object of a class
182
Inheritance is a way of building a new class from scratch.
False
183
What will be the result of executing the following code? class A: def __str__(self): return 'a' class B: def __str__(self): return 'b' class C(A, B): pass o = C() print(o)
it will print a
183
What will be the result of executing the following code? try: raise Exception(1,2,3) except Exception as e: print(len(e.args))
it will print 3
184
What will be the result of executing the following code? class A: def __init__(self): pass a = A(1) print(hasattr(a,'A'))
it will raise an exception
185
Class variables are stored outside any object and exist in just one copy.
True
186
What is the purpose of the __init__ method in Python?
To initialize the object's internal state and create instance variables
186
What is the __dict__ property in Python classes and objects?
A dictionary that stores the names and values of all properties in the class or object
187
What is encapsulation in object-oriented programming?
Encapsulation is the process of hiding data and methods within a class, allowing access only through defined interfaces.
188
Python looks for object components by first searching inside the object itself and then in its superclasses, from top to bottom.
False
189
Classes in object-oriented programming can inherit properties and methods from their subclasses.
False
190
What does the isleap function in the calendar module do?
Checks whether a year is a leap year or not
190
Which function in the time module suspends program execution for a given number of seconds?
sleep
191
The write() method in Python writes a string to a text file.
True
192
What is the expected result of the following code? import os os.mkdir('pictures') os.chdir('pictures') os.mkdir('thumbnails') os.chdir('thumbnails') os.mkdir('tmp') os.chdir('../') print(os.getcwd())
It prints the path to the pictures directory
193
A Python generator is a piece of specialized code that forces memory to be reallocated.
False
194
What is the expected result of the following code? from datetime import datetime datetime = datetime(2019, 11, 27, 11, 27, 22) print(datetime.strftime('%y/%B/%d %H:%M:%S'))
19/November/27 11:27:22
195
What does the uname function from the os module return?
An object containing information about the current operating system
196
What is the difference between a function and a generator in Python?
A function returns one well-defined value, while a generator returns a series of values
197
What does the today method return?
A date object representing the current local date.
197
The range() function is a generator and an iterator.
True
198
What is the Unix epoch?
The starting point for counting time on Unix systems.
199
Which function in the os module allows you to recursively create directories?
makedirs
200
Which os module attribute returns the hardware identifier?
machine
200
What is a lambda function in Python?
An anonymous function that can be used to simplify and make code clearer
201
What does the listdir() function return?
A list containing the names of the files and directories in the specified path
202
Which of the following methods is used to read a specified number of characters/bytes from a file and return them as a string?
read()
202
What keyword would you use to define an anonymous function?
lambda
203
What is the expected result of executing the following code? def fun(n): s = '+' for i in range(n): s += s yield s for x in fun(2): print(x, end='');
It will print ++++++
204
The today method in the datetime module returns a date object representing the current local date.
True
204
What is the meaning of the value represented by errno.EEXIST ?
File exists
204
What does the '*' symbol represent when importing a module in Python?
It imports all entities from the specified module
205
Which statement is true about the pip search command?
It needs a working Internet connection to work.
205
The __pycache__ directory is automatically created when a module is imported for the first time.
True
206
The math module in Python provides functions for trigonometry operations like sine, cosine, and tangent.
True
206
Which command is used to install a package system-wide with pip?
pip install name
207
What does it mean to mark a variable name with an underscore or double underscore?
To indicate that the variable should be treated as private
208
What is true about the pip install command?
It allows the user to install a specific version of the package.
208
Which statement is true about the pip search command?
It searches through all PyPI packages.
209
What is true about the pip install command?
It installs a package per user only when the --user option is specified.
210
The Python Package Index (PyPI) is a centralized repository of available software packages.
True
210
What does the machine() function in the platform module return?
The generic name of the processor
211
Data mining is one of the most promising modern scientific disciplines that utilizes Python.
True
212
What is the purpose of a package in Python?
To couple together related modules under one common name
213
What is a module in Python?
A container filled with functions
214
Which command is used to install a package system-wide with pip?
pip install name
215
A module is a file containing Python definitions and statements.
True
215
You can import a module using the 'import' keyword.
True
216
Where can you find a directory of modules available in the Python universe?
Python Module Index
216
Knowing that a function named fun() resides in a module named mod, and it has been imported using the following line, choose the way it can be invoked in your code. import mod
mod.fun()
216
What is a module in Python?
A file containing Python definitions and statements that can be imported and used when necessary
217
A module is a kind of container that can hold multiple functions.
True
217
What is true about updating already installed Python packages?
It's performed by the install command accompanied by the -U option.
217
A predefined Python variable that stores the current module name is called _____.
__name__
218
The math module in Python provides functions for trigonometry operations like sine, cosine, and tangent.
True
218
What does pip stand for?
pip installs packages
218
What is the significance of Python being open-source software?
It allows for the free exchange of code and experiences among Python community members
219
What is the name of the repository that collects and shares free Python code?
Python Package Index (PyPI)
219
How can you give an imported module a different name in Python?
By using the 'as' keyword followed by the desired name
219
How does Python translate a module's source code?
It translates it into a semi-compiled format stored in pyc files
220
When a module is imported, its contents _____.
are executed once (implicitly)
220
When importing a module, you can give it an alias using the 'with' keyword.
False
221
What is the purpose of the random module in Python?
To operate with pseudorandom numbers
222
Which of the following is a hyperbolic function in the math module?
sinh(x)
222
The digraph written as #! is used to _____.
tell a Unix or Unix-like OS how to execute the contents of a Python file
222
What does the random() function in the random module do?
Produces a float number from the range (0.0, 1.0)
222
What is the purpose of the __init__.py file in a package?
To initialize the package and/or its sub-packages
223
Why is importing the entire module using the '*' symbol not recommended in Python?
It can lead to naming conflicts and make the code harder to understand
223
What is the tool used to access the Python Package Index (PyPI)?
pip
224
Which statement is true about the pip search command?
It needs a working Internet connection to work.
224
What will be the effect of running the following code? class A: def __init__(self,v): self.__a = v + 1 a = A(0) print(a.__a)
The code will raise an AttributeError exception
224
Which module should you import to work with dates and times?
datetime
224
What is the expected value assigned to the result variable after the following code is executed? import math result = math.e != math.pow(2, 4) print(int(result))
1
224
How can you change the first day of the week in the calendar module?
By using the setfirstweekday function
224
How does Python find properties and methods when accessing an object's entity?
It looks inside the object itself and all classes in its inheritance line
225
Which snippet would you insert in order for the program to output the following: (1, 4, 27) my_list = [1, 2, 3] Insert line of code here. print(foo)
foo = tuple(map(lambda x: x**x, my_list))
225
The map() function applies a specified function to all elements of a given list and returns an iterator with the results.
True
226
What is the purpose of the hasattr() function in Python?
To check if an object or class contains a specified property
226
What is the expected result of the following code? import os os.mkdir('pictures') os.chdir('pictures') os.mkdir('thumbnails') os.chdir('thumbnails') os.mkdir('tmp') os.chdir('../') print(os.getcwd())
It prints the path to the pictures directory
226
Which snippet would you insert in order for the program to output the following: Mo Tu We Th Fr Sa Su import calendar Insert line of code here.
print(calendar.weekheader(2))
226
What is the purpose of the timedelta object?
To perform calculations on date and datetime objects
227
What is the expected result of executing the following code? def fun(n): s = '+' for i in range(n): s += s yield s for x in fun(2): print(x, end='');
It will print ++++++
227
A Python generator is a piece of specialized code that forces memory to be reallocated.
False
227
What is encapsulation in object-oriented programming?
Encapsulation is the process of hiding data and methods within a class, allowing access only through defined interfaces.
228
The write() method in Python writes a string to a text file.
True
228
A stack uses the LIFO (Large In, First Out) model.
True
228
What does the today method return?
A date object representing the current local date.
228
Which method can be used to write a string to a text file?
write()
228
Which attribute of the os module allows you to distinguish the operating system?
name
229
What will be the result of executing the following code? class Ex(Exception) def __init__(self, msg): Exception.__init__(self, msg + msg) self.args = (msg,) try: raise Ex('ex') except Ex as e: print(e) except Exception as e: print(e)
it will raise an unhandled exception
230
Different objects of the same class may possess different sets of instance variables.
True
231
Python can only be used for object programming, not procedural programming.
False
231
The movedir() function in Python is used to move between directories by changing the current working directory to the specified path.
False
232
The read() method in Python reads the number characters/bytes from a file and returns them as a string.
True
233
The range() function is a generator and an iterator.
True
233
The isinstance() function in Python checks if an object is an instance of a particular class.
True
233
The is operator checks if two variables refer to the same object in memory.
True
234
A data structure described as LIFO is actually a _____.
Stack
234
What does the isleap function in the calendar module do?
Checks whether a year is a leap year or not
234
The time class in the time module accepts six optional arguments: hour, minute, second, microsecond, tzinfo, and fold.
True
235
What will be the result of executing the following code? class I: def __init__(self): self.s = 'abc' self.i = 0 def __iter__(self): return self def __next__(self): if self.i == len(self.s): raise StopIteration v = self.s[self.i] self.i += 1 return v for x in I(): print(x,end='')
it will print abc
236
What is the yield statement in Python?
A statement used inside functions to suspend function execution and return the yield's argument as a result
236
What is inheritance in object programming?
A practice of passing attributes and methods from a superclass to a subclass
237
What is the difference between a regular method and a constructor in Python?
A constructor is a method named __init__ that is automatically invoked when an object is instantiated
237
Encapsulation in object-oriented programming allows for the hiding and protection of selected values.
True
238
What will be the result of executing the following code? class A: def a(self): print('a') class B: def a(self): print('b') class C(B,A): def c(self): self.a() o = C() o.c()
it will print b
239
What is the self parameter used for in Python methods?
To obtain access to instance and class variables
240
What is the main difference between the procedural and object-oriented approach to programming?
The procedural approach separates data and code, while the object-oriented approach combines them in classes.
241
What is the purpose of the __init__ method in Python?
To initialize the object's internal state and create instance variables
242
Which of the following methods is used to read a specified number of characters/bytes from a file and return them as a string?
read()
243
How does Python find properties and methods when accessing an object's entity?
First inside the object itself, then in all classes involved in the object's inheritance line from bottom to top