Integrating you Infrastructure Security Week 4 Flashcards

(10 cards)

1
Q

Which of the following is NOT a Python data structure?

A

Def

Def is not a Python data structure; it is a keyword used to define functions.

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

Which of the following are valid Python data types?

A

float
int
str

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

a = [“hello”, True]
In the code above, what is the data type of the variable “a”?

A

List

The variable “a” is a list containing elements of different data types.

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

for x in range (1,10):
print(x)
CODE
Which of the following will be the last number printed from the code snippet featured above?

A

9

The **range(1, 10) **function generates numbers starting from 1 up to 9 (inclusive of the start and exclusive of the end). Therefore, the last number printed by the loop will be 9.

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

A list can collect different data types. For example: my_list = [1,
“1”, True, {“name”:”Adi”}].

A

True

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

Which variable type is the “x” in the following code? x = “15”?

A

String

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

with open (“MyFile.txt”, “w”) as file:
file.write(“Hello World”)
CODE

A

“Hello World” is written inside MyFile.txt.

The code opens “MyFile.txt” in write mode, writes “Hello World” into it, and then automatically closes the file due to the use of the with statement.

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

What is the correct way to add a new value to a dictionary?

A

dict[“name”] = “John”

To add a new key-value pair to a dictionary in Python, you need assign a value to a new or existing key specifying the key in square brackets.

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

x= [“H”, “E”, “L”, “L”,”O”]
print(x[1:4])
CODE
Which of the following would be the output of the code snippet featured above?

A

[“E”, “L”, “L”]

The code uses Python’s slice notation to get elements from index 1 to index 3 (inclusive of the start index and exclusive of the end index) from the list x. Therefore, the output will be** [“E”, “L”, “L”].**

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

Which of the following loops will run for a specified number of iterations?

A

For loop.

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