ITlec Prelims pt1 Flashcards

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
Q

can be followed by an optional else statement, which executes when the boolean expression is FALSE.

A

An if statement

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

contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value.

A

else statement

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

allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.

A

The elif statement

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

allows us to execute a statement or group of statements multiple times

A

loop statement

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

Repeats a statement or group of statements while a given condition is TRUE

A

while loop

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

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

A

F
Loop iterates when condition is true

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

A loop becomes ____________ if a condition never becomes FALSE.

A

infinite loop

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

If the _________ statement is used with a for loop, the ____ statement is executed when the condition becomes false.

A

else

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

Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

A

For loop

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

is a block of organized, reusable code that is used to perform a single, related action.

A

A function

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

The code block within every function starts with a ___________ and is ___________

A

colon (:) and is indented.

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

The statement __________ exits a function, optionally passing back an expression to the caller

A

return [expression]

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

A return statement with no argument returns an error

A

False
It returns as None

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

______________ can be accessed only inside the function in which they are declared,

A

local variables

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

__________ can be accessed throughout the program body by all functions.

A

global variables

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

is a Python object with arbitrarily named attributes that you can bind and reference.

A

A module

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

You can use any Python source file as a module by executing an _______________ in some other Python source file.

A

import statement

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

The ________ built-in function returns a sorted list of strings containing the names defined by a module.

A

dir()

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

powerful and flexible data structure in python that allows you to store and manipulate collections of elements

A

Lists

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

Python lists can grow or shrink in size as needed making them flexinle for handling varying amounts of data

A

Dynamic storage and retrieval

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

Lists are commonly used in _____ to iterate over the elements and perform operations on them

46
Q

to create a python list you need to use ____

A

[] square brackets

47
Q

List elements are accessed using their ________

48
Q

the indices start from ____ for the first elements

49
Q

Lists can store elements of any data types
T or F

50
Q

This list function return the number of elements present in a list

51
Q

allows you to add an element at the end of the list

52
Q

adds elements from another list to the end of the current list.

53
Q

allows you to insert an element at a specific index in the list

54
Q

function is used to remove the first occurrence of a specified element from the list

55
Q

used to remove and return the element at a specific index in a list

56
Q

removes all elements from the list

57
Q

returns the index of the first occurrence of a specified element in the list

58
Q

returns the number of occurrences a specific element in the list

59
Q

used to sort in the list ascending order.

60
Q

reverses the order of elements in the list

61
Q

creates a shallow copy of the list

62
Q

provide a powerful set of tools for manipulating and managing lists

A

list functions

63
Q

a concise and pythonic way of generating lists

A

List comprehension

64
Q

List comprehension does not allow it to be nested
T or F

A

F
it is allowed to be nested to allow complex lists

65
Q

is used to apply the int() function to each element to in the input list

66
Q

used to include only certain elements

67
Q

this is generally faster and more efficient compared to traditional loops when dealing with simple operations on lists

A

List comprehension

68
Q

an ORDERED collection of elements enclosed in parentheses ()

69
Q

Tuples are immutable
True or false

70
Q

Elements cannot be modified once they are defined

71
Q

tuples are typically created by enclosing elements within ____ and separating them with _________

A

parentheses ()
Comma ,

72
Q

Individual elements within a tuple can be accessed using __________

73
Q

involves creating a tuple by assigning values to it

A

tuple packing

74
Q

allows you to assign individual elements of a tuple to separate variables

A

tuple unpacking

75
Q

Tuples can be concatenated using the “*” operator?
T or F

A

False you use “+”

76
Q

Tuples can be repreated using the “x” operator
T or F

A

False you use the “*”

77
Q

to check if an element exists in a tuple use the _____ keyword

78
Q

tuples are _______, meaning their element cannot be changed after creation

79
Q

you can convert lists and vice versa using the list() and tuple() function
T or F

80
Q

Functions can only return single values as a tuple
T or F

A

False it can return multiple values

81
Q

is an immutable unordered collection of UNIQUE elements

82
Q

Sets are widely used for performing ___________ such as union, intersection and difference

A

mathematical set operations

83
Q

sets can be created using _________

A

curly braces {}

84
Q

You can use this function to add a single element in a set

85
Q

you can use this fucntion to add multiple elements in a set

86
Q

removes specified element from the set if it does not exist it will raise an error

87
Q

this removes an element and if it does not exist it will not raise an error

88
Q

removes a random item from a set

89
Q

This set operations combines returns a combination of two sets

90
Q

symbol of union

91
Q

This set operation return what’s common between two sets

A

Intersection

92
Q

Symbol of intersection

93
Q

returns the difference between 2 sets or more

A

difference

94
Q

symbol of difference

95
Q

returns what is unique in both sets

A

Symmetric difference

96
Q

symbol of symmetric difference

97
Q

to test if a set is a subset use

A

issubset()

98
Q

to test if a set is a superset use

A

issuperset()

99
Q

Sets only store unique elements, you can use them to store duplicates.
T or F

100
Q

Allows you to store and retrieve data in key-value pairs

A

Dictionary

101
Q

Another name of dictionary

A

Associative array or hash table

102
Q

T or F
Dictionary is an ordered collection

A

F it is unordered

103
Q

Dictionary key must be ______ and ______

A

unique and immutable

104
Q

Dictionaries are created using

A

{} curly braces

105
Q

To retrieve the value associated with a specific key use the _________

A

square bracket [] with the key inside

106
Q

If you try to access a key that does not exist it will raise an index error
T or F

A

F it will raise a KeyError

107
Q

You can use the ______ method which returns a default value if they key is not found

108
Q

to remove an element from the dictionary you can use the

A

pop() or del Keyword

109
Q

to copy a dictionary use

A

copy() or dict() constrictor

110
Q

the most common approach is to loop through its keys
T or F

111
Q

How is dict separated

A

it is separated by colon (:), and the elements are separated by commas (,)