IT101-2 Finals Flashcards

(247 cards)

1
Q

Who created python?

A

Guido Van Rossum

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

When was python created?

A

1991

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

What is python used for?

A

web development (server-side),
software development,
mathematics,
system scripting.

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

Whenever you are done in the python command line, you can simply type __________ to quit the python command line.

A

exit()

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

*indicate a block of code.

A

Indentations

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

Comments start with a ______, and Python will render the rest of the line as a comment

A

#

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

A _________ is created the moment you first assign a value to it.

A

variable

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

Rules of variables

A
  • Must start with letter or underscore
    -can’t start with number
    -can only contain alpha numeric and underscore
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

There are three numeric types in Python:

A

*int
*float
*complex

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

is a named place in the memory where a programmer can store data and later retrieve the data using the variable “name”

A

variable

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

You can change the contents of a variable in a later statement
T or F

A

T

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

We assign a value to a variable using the ________?

A

Assignment statement (=)

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

Order of operation for python

A

Pemdas
Parenthesis
Exponent
multiplication, division, and remainder
Addition subtraction
(from left to right)

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

When writing code - use __________

A

parenthesis

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

You can also use str() and float() to convert between strings and integers

True or False

A

False
int() and float()

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

you will not get an error if the string does not contain numeric characters while converting to int or float

T or F

A

F
You will get an Error

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

used to output variables

A

print()

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

execution of code statements (one line after another) – like following a recipe

A

Sequential

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

used for decisions, branching – choosing between 2 or more alternative paths.

A

Selection

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

used for looping

A

repetition

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

Recall that Python has a type called __________, which can take two possible values, True and False

A

boolean

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

An expression that evaluates to a true/false value is called a

A

Boolean expression

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

Python, decisions are made with the ___________, also known as the __________________.

A

if statement
selection statement

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

If the boolean expression evaluates to TRUE, then the block of statement(s) inside the if statement is executed. If boolean expression evaluates to FALSE, then the first set of code after the end of the if statement(s) is executed

T or F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
can be followed by an optional else statement, which executes when the boolean expression is FALSE.
An if statement
26
contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value.
else statement
27
allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.
The elif statement
28
allows us to execute a statement or group of statements multiple times
loop statement
29
Repeats a statement or group of statements while a given condition is TRUE
while loop
30
The loop iterates while the condition is false. When the condition becomes true, program control passes to the line immediately following the loop. T or F
F Loop iterates when condition is true
31
A loop becomes ____________ if a condition never becomes FALSE.
infinite loop
32
If the _________ statement is used with a for loop, the ____ statement is executed when the condition becomes false.
else
33
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
For loop
34
is a block of organized, reusable code that is used to perform a single, related action.
A function
35
The code block within every function starts with a ___________ and is ___________
colon (:) and is indented.
36
The statement __________ exits a function, optionally passing back an expression to the caller
return [expression]
37
A return statement with no argument returns an error
False It returns as None
38
______________ can be accessed only inside the function in which they are declared,
local variables
39
__________ can be accessed throughout the program body by all functions.
global variables
40
is a Python object with arbitrarily named attributes that you can bind and reference.
A module
41
You can use any Python source file as a module by executing an _______________ in some other Python source file.
import statement
42
The ________ built-in function returns a sorted list of strings containing the names defined by a module.
dir()
43
powerful and flexible data structure in python that allows you to store and manipulate collections of elements
Lists
44
Python lists can grow or shrink in size as needed making them flexinle for handling varying amounts of data
Dynamic storage and retrieval
45
Lists are commonly used in _____ to iterate over the elements and perform operations on them
loops
46
to create a python list you need to use ____
[] square brackets
47
List elements are accessed using their ________
indices
48
the indices start from ____ for the first elements
49
Lists can store elements of any data types T or F
t
50
This list function return the number of elements present in a list
len()
51
allows you to add an element at the end of the list
append()
52
adds elements from another list to the end of the current list.
extend()
53
allows you to insert an element at a specific index in the list
insert()
54
function is used to remove the first occurrence of a specified element from the list
remove()
55
used to remove and return the element at a specific index in a list
pop()
56
removes all elements from the list
clear()
57
returns the index of the first occurrence of a specified element in the list
index()
58
returns the number of occurrences a specific element in the list
count()
59
used to sort in the list ascending order.
sort()
60
reverses the order of elements in the list
reverse()
61
creates a shallow copy of the list
copy()
62
provide a powerful set of tools for manipulating and managing lists
list functions
63
a concise and pythonic way of generating lists
List comprehension
64
List comprehension does not allow it to be nested T or F
F it is allowed to be nested to allow complex lists
65
is used to apply the int() function to each element to in the input list
map()
66
used to include only certain elements
filter()
67
this is generally faster and more efficient compared to traditional loops when dealing with simple operations on lists
List comprehension
68
an ORDERED collection of elements enclosed in parentheses ()
Tuples
69
Tuples are immutable True or false
t
70
Elements cannot be modified once they are defined
Immutable
71
tuples are typically created by enclosing elements within ____ and separating them with _________
parentheses () Comma ,
72
Individual elements within a tuple can be accessed using __________
indexing
73
involves creating a tuple by assigning values to it
tuple packing
74
allows you to assign individual elements of a tuple to separate variables
tuple unpacking
75
Tuples can be concatenated using the "*" operator? T or F
False you use "+"
76
Tuples can be repreated using the "x" operator T or F
False you use the "*"
77
to check if an element exists in a tuple use the _____ keyword
in
78
tuples are _______, meaning their element cannot be changed after creation
immutable
79
you can convert lists and vice versa using the list() and tuple() function T or F
t
80
Functions can only return single values as a tuple T or F
False it can return multiple values
81
is an immutable unordered collection of UNIQUE elements
set
82
Sets are widely used for performing ___________ such as union, intersection and difference
mathematical set operations
83
sets can be created using _________
curly braces {}
84
You can use this function to add a single element in a set
add()
85
you can use this fucntion to add multiple elements in a set
update()
86
removes specified element from the set if it does not exist it will raise an error
remove()
87
this removes an element and if it does not exist it will not raise an error
discard()
88
removes a random item from a set
pop()
89
This set operations combines returns a combination of two sets
Union
90
symbol of union
|
91
This set operation return what's common between two sets
Intersection
92
Symbol of intersection
&
93
returns the difference between 2 sets or more
difference
94
symbol of difference
-
95
returns what is unique in both sets
Symmetric difference
96
symbol of symmetric difference
\^
97
to test if a set is a subset use
issubset()
98
to test if a set is a superset use
issuperset()
99
Sets only store unique elements, you can use them to store duplicates. T or F
t
100
Allows you to store and retrieve data in key-value pairs
Dictionary
101
Another name of dictionary
Associative array or hash table
102
T or F Dictionary is an ordered collection
F it is unordered
103
Dictionary key must be ______ and ______
unique and immutable
104
Dictionaries are created using
{} curly braces
105
To retrieve the value associated with a specific key use the _________
square bracket [] with the key inside
106
If you try to access a key that does not exist it will raise an index error T or F
F it will raise a KeyError
107
You can use the ______ method which returns a default value if they key is not found
get()
108
to remove an element from the dictionary you can use the
pop() or del Keyword
109
to copy a dictionary use
copy() or dict() constrictor
110
the most common approach is to loop through its keys T or F
T
111
How is dict separated
it is separated by colon (:), and the elements are separated by commas (,)
112
Question
Answer
113
a sequence of characters
string
114
computers do not deal with characters they deal with___________
numbers (binary)
115
Conversion of character to number is called ______ and the reverse is called ___________
encoding decoding
116
___________ and _________ are some of the popular encodings used.
ASCII and Unicode
117
In python a string is a sequence of _________ characters
unicode
118
was introduced to include every character in all languages and bring uniformity in encoding
Unicode
119
You can access individual characters using
indexing
120
Trying to access a char out of index range will raise an
indexerror
121
An index must be an integer any other type will result in
TypeError
122
Strings are Immutable T or F
T
123
To delete tge string entirely is possible using the
del keyword
124
returns an enumerate object, it contains the index and value of all the items
enumerate()
125
starts with a backslash and is interpreted differently
escape sequence
126
To ignore the escape sequence inside a string place a
r or R infront of the string
127
is available with the string object is very versatile and powerful for FORMATTING strings
format()
128
format strings contain ___________ as place holders
curly braces{}
129
Format are separated from the field name using
Colon
130
is a module to manipulate and manage date and time information
datetime
131
the handling for date time is
datetime.datetime
132
you need to import datetime before ytou use it T or F
T
133
To format datetime objects use
strftime()
134
to perfrom arithmetic operations in datetime use
timedelta
135
to work with timezones in datetime objects use
pytz library
136
are named locations on disk to store related information
Files
137
store the data in the form of characters.
Text files
138
store entire data in the form of bytes.
Binary files
139
are generally available in .jpg, .gif or .png formats.
Image files
140
CRUD meaning
Creat read update delete
141
we use _________ function to open a file
open()
142
represents a temporary block of memory
buffer
143
What does w open mode does?
Write data into file
144
What does "r" does
Read data from the file
145
What does a does?
append data to the file?
146
What does w+ do?
to write and read data of a file
147
What does r+ do?
To read and write data into file
148
What does a+ do?
To append and read data of file.
149
What does x do?
open file in exclusing creation mode.
150
To close a file use __________
close()
151
closing is mandatory T or F
t
152
When a file is not closed a problem will lead to
insufficient memory.
153
to create a fille use
open() method
154
to create a new file which parameters do you need?
x a W
155
TO read data from text file use
read()
156
the____________ method returns a list of remaining lines of the entire file
readlines()
157
To delete you much import
the os module and run the os.remove() function
158
to know the current directory
os.getcwd()
159
to make a sub directory
os.mkdir('mysub')
160
to change directory
os.chdir()
161
to rmeove directory
os.rmdir()
162
to rename directory
os.rename()
163
what is the error if not found using os.chdir()
FileNotFoundError
164
What happens when you delete a directory that has something inside of it
OSERROR
165
What does csv mean?
Comma separated Value
166
Do you need to import a csv file to use it? T or F
T
167
how to read in csv
csv.reader()
168
How to write in csv
csv.writer()
169
how to write a row of data in csv
writerow()
170
disrupts the flow of instructions
exception
171
this is optional and is used for code that needs to be executed regardless of whether an exception occurred or not
Finally
172
you can raise exceptions using the
raise statement
173
What does function overloading mean (in python)? The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved. An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle. the function overloads and kills the computer A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.
The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
174
Which of these is not a fundamental features of OOP? Encapsulation Instantiation Inheritance Polymorphism
Instantiation
175
Which of the following best describes inheritance? Means of bundling instance variables and methods in order to restrict access to certain class members Focuses on variables and passing of variables to functions Allows for implementation of elegant software that is well designed and easily modified Ability of a class to derive members of another class as a part of its own definition
Ability of a class to derive members of another class as a part of its own definition
176
Which of the following is the most suitable definition for encapsulation? Focuses on variables and passing of variables to functions Means of bundling instance variables and methods in order to restrict access to certain class members Allows for implementation of elegant software that is well designed and easily modified Ability of a class to derive members of another class as a part of its own definition
Means of bundling instance variables and methods in order to restrict access to certain class members
177
Which of the following is required to create a new instance of the class? A value-returning method A constructor A None method A class
A constructor
178
Which of the following statements is most accurate for the declaration x = Circle()? x contains an object of the Circle type. x contains an int value. x contains a reference to a Circle object. You can assign an int value to x.
x contains a reference to a Circle object.
179
Which of the following best describes polymorphism? Means of bundling instance variables and methods in order to restrict access to certain class members Focuses on variables and passing of variables to functions Ability of a class to derive members of another class as a part of its own definition Allows for objects of different types and behaviour to be treated as the same general type
Allows for objects of different types and behaviour to be treated as the same general type
180
Which of the following represents a template, blueprint, or contract that defines objects of the same type? A method A class An object A data field
A class
181
Which of the following best describes inheritance? Focuses on variables and passing of variables to functions. Allows for implementation of elegant software that is well designed and easily modified. Means of bundling instance variables and methods in order to restrict access to certain class members. Ability of a class to derive members of another class as a part of its own definition.
Ability of a class to derive members of another class as a part of its own definition.
182
Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write? B.__init__(self) A.__init__(self) B.__init__(A) A.__init__(B) Q
A.__init__(self)
183
What is Instantiation in terms of OOP terminology? Modifying an instance of class Deleting an instance of class Creating an instance of class Copying an instance of class
Creating an instance of class
184
Which of the following statements are correct? An object can contain the references to other objects. A reference variable refers to an object. An object may contain other objects. A reference variable is an object.
An object can contain the references to other objects. Correct: A reference variable refers to an object.
185
What is an instance in python? A running program. The creation of an instance of a class. A special kind of function that is defined in a class definition. An individual object of a certain class.
An individual object of a certain class.
186
What is the purpose of a constructor in Python? To declare variables. To handle exceptions. To initialize objects when they are created. To define methods.
To initialize objects when they are created.
187
In Python, polymorphism enables objects of different classes to be treated as instances of a common_________
superclass
188
What is polymorphism in object-oriented programming, and how does it benefit software design?
Answer Polymorphism allows us to use methods in a child class that have the same named method in the parent class, it benefits software design by allowing methods to be reusable by being used interchangeably in different classes, it allows the code to be used more flexibly, which lets it be maintained easily.
189
Encapsulation helps protect the internal state of an object from unauthorized access. T True F False
T
190
Classes can be instantiated multiple times to create multiple objects. T True F False
T
191
A constructor in Python is defined using the ___________ method.
__init__
192
Inheritance allows a derived class to have access to private members of the base class by default. T True F False
F
193
Field
Variable that stores the state of an object. Variable that stores the state of an object.
194
Object
Instance of a class.
195
Interface
A common method signature for implementation.
196
Decorator
Decorator
197
1 Single Inheritance
A subclass inherits from one superclass.
198
2 Multilevel Inheritance
A subclass inherits from another subclass.
199
Abstract Method
Declared but not implemented in the abstract class.
200
Concrete Method
Fully implemented method that can be used.
201
In Python, all methods must have a return type specified. T True F False
F
202
Which of the following is NOT a principle of object-oriented programming? Abstraction. Multiple Inheritance. Encapsulation. Polymorphism.
Multiple Inheritance.
203
Encapsulation
Using private variables with getters and setters.
204
2 Inheritance
A Dog class inherits from an Animal class.
205
3 Polymorphism
Different shapes implementing a draw() method.
206
4 Constructor Overloading
Using default parameters in constructors.
207
The ______ parameter in Python methods refers to the instance of the class.
self
208
Encapsulation involves bundling data and methods within a single unit called a _______
class.
209
Explain the concept of encapsulation in object-oriented programming. How does it contribute to the security and maintainability of code?
Answer Encapsulation is the bundling of data and methods that operate in a single unit. Encapsulation contributes to security and maintainability of code by restricting access of the data, making it harder for outsiders to get access to the data.
210
Abstraction
Simplifying complex reality.
211
2 Method Overriding
Subclass provides specific implementation for an inherited method.
212
3 Data Hiding
Restricting access to certain attributes.
213
4 Dynamic Typing
Variables can change data type.
214
Inheritance allows a class to inherit properties and behaviors from another class, referred to as the
base class
215
class 2 def 3 super() 4 @property
Defines a new class. Defines a new method. Calls a method from the superclass. Creates a getter method.
216
Classes 2 Encapsulation 3 Inheritance 4 Methods
Blueprints for creating objects. Hiding the internal state of an object. Acquiring properties from another class. Functions that define the behavior of objects.
217
An abstract class cannot be instantiated directly and serves as a ____________ for other classes.
blueprint
218
What is the Syntax to create a Frame ? win.frame(options) Frame(window,options) Both of the above None of the above
Frame(window,options)
219
Correct way to draw a line in canvas tkinter ? create_line(canvas) line() canvas.create_line() None of the above
canvas.create_line()
220
Which of the following is correct ? GUI is the part of the canvas Both of the above None of the above canvas is the part of the GUI
canvas is the part of the GUI
221
It is a container used for grouping and organizing the widgets. All of the above canvas window frame
frame
222
How we import a tkinter in python program ? from tkinter import * import tkinter import tkinter as t All of the above
All of the above
223
Creating line are come in which type of thing ? GUI Canvas None of the above Both of the above
Canvas
224
A window is an instance of tkinter’s Tk class. T True F False
T True
225
How pack() function works on tkinter widget ? None of the above According to left,right,up,down According to row and column vise According to x,y coordinate
According to left,right,up,down
226
Which of the following geometry managers are available in tkinter? choose 3 answers .grid() .flex() .table() .place() .pack()
.grid() .place() .pack()
227
What we use to change the back ground color any widget ? background bground bg fg
bg
228
Tkinter tool in python provide the GUI Database OS commands All of the above
GUI
229
How the grid() function put the widget on the screen ? None of the above According to x,y coordinate According to row and column vise According to left,right,up,down
According to row and column vise
230
It is a method we use to hold the screen waiting for events to happen ? mainloop() function Stop() function None of the above pause() function Q
mainloop() function
231
How the place() function put the widget on the screen ? According to x,y coordinate According to row and column vise None of the above According to left,right,up,down
According to x,y coordinate
232
What is the use of the pack() function for the tkinter widget ? To define a size of the widget To perform a task by a widget To organize the widgets in blacks before placing them on the screen To destroy the widget
To organize the widgets in blacks before placing them on the screen
233
To change the color of the text in the Label widget, what we use ? bg cchng color fg
fg
234
fg in tkinter widget is stands for ? foreground forgap forgrid background
a
235
Essential thing to create a window screen using tkinter python? To define a geometry All of the above call tk() function create a button
c
236
For what purpose, the bg is used in Tkinter widget ? To change the color of widget To change the size of widget To change the background of widget To change the bordergrid of widget
c
237
GUI stands for Global user interaction Graph user interaction Graphical user interaction Graphical user interface
D
238
Which of the correct way to set the geometry of the window ? geometry(x y) geometry("300x400") geometry(300,400) geometry(300;400)
B
239
To get the multiple line user data, which widget we use ? Entry Text Label Canvas
B
240
Which of the following function are used to get the data from the Entry field in Python Tkinter ? get() gettext() getdata() getEntry()
A
241
Which of the following is used to call a function by the Button widget in tkinter python ? call command contact execute
B
242
To delete any widget from the screen which function we use ? stop() delete() destroy() break()
C
243
What is the correct syntax of destroy in tkinter ? destroy(object) object.destroy() object(destroy) delete(object)
B
244
Which of the following we can able to delete using destroy() function ? I. Button II. Label III. Frame I only I and II II and III I, II and III
D
245
Text widget refers to the multi-line and non-editable text. T True F False
F
246
Which of the following is clickable in GUI programming ? I. Button II. Checkbutton III. Label I only I and II II and III I, II, and III
B
247