Integrating you Infrastructure Security Week 4 Flashcards
(10 cards)
Which of the following is NOT a Python data structure?
Def
Def is not a Python data structure; it is a keyword used to define functions.
Which of the following are valid Python data types?
float
int
str
a = [“hello”, True]
In the code above, what is the data type of the variable “a”?
List
The variable “a” is a list containing elements of different data types.
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?
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.
A list can collect different data types. For example: my_list = [1,
“1”, True, {“name”:”Adi”}].
True
Which variable type is the “x” in the following code? x = “15”?
String
with open (“MyFile.txt”, “w”) as file:
file.write(“Hello World”)
CODE
“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.
What is the correct way to add a new value to a dictionary?
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.
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?
[“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”].**
Which of the following loops will run for a specified number of iterations?
For loop.