commands Flashcards
(53 cards)
What is the command to print ‘Hello, World!’ in Python?
print(‘Hello, World!’)
True or False: In Python, indentation is used to define blocks of code.
True
Fill in the blank: The command to create a list in Python is ________.
list()
What is the syntax for defining a function in Python?
def function_name(parameters):
Which command is used to read a file in Python?
open()
What will the following command return? len([1, 2, 3])
3
What is the command to generate a random integer between 1 and 10?
import random; random.randint(1, 10)
True or False: Lists in Python are immutable.
False
What is the purpose of the ‘import’ statement in Python?
To include external modules and libraries in your code.
Fill in the blank: The command to create a dictionary in Python is ________.
dict()
Which keyword is used to create a loop that iterates over a sequence in Python?
for
What is the output of the command: print(type(5.0))?
<class ‘float’>
What command is used to handle exceptions in Python?
try…except
Multiple choice: Which of the following is a valid variable name in Python? A) 1st_variable B) first-variable C) first_variable
C) first_variable
What is the command to convert a string to an integer in Python?
int()
True or False: The ‘while’ loop will execute at least once.
False
What is the command to remove an item from a list in Python?
list.remove(item)
Fill in the blank: The command to sort a list in Python is ________.
list.sort()
What is the function used to find the maximum value in a list?
max()
What will the following command return? ‘Python’.lower()
‘python’
Multiple choice: Which of the following methods can be used to add an item to a list? A) append() B) add() C) insert()
A) append() and C) insert()
What is the command to create a tuple in Python?
tuple()
What is the purpose of the ‘return’ statement in a function?
To exit the function and optionally pass an expression back to the caller.
True or False: Strings in Python are mutable.
False