commands Flashcards

(53 cards)

1
Q

What is the command to print ‘Hello, World!’ in Python?

A

print(‘Hello, World!’)

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

True or False: In Python, indentation is used to define blocks of code.

A

True

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

Fill in the blank: The command to create a list in Python is ________.

A

list()

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

What is the syntax for defining a function in Python?

A

def function_name(parameters):

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

Which command is used to read a file in Python?

A

open()

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

What will the following command return? len([1, 2, 3])

A

3

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

What is the command to generate a random integer between 1 and 10?

A

import random; random.randint(1, 10)

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

True or False: Lists in Python are immutable.

A

False

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

What is the purpose of the ‘import’ statement in Python?

A

To include external modules and libraries in your code.

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

Fill in the blank: The command to create a dictionary in Python is ________.

A

dict()

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

Which keyword is used to create a loop that iterates over a sequence in Python?

A

for

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

What is the output of the command: print(type(5.0))?

A

<class ‘float’>

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

What command is used to handle exceptions in Python?

A

try…except

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

Multiple choice: Which of the following is a valid variable name in Python? A) 1st_variable B) first-variable C) first_variable

A

C) first_variable

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

What is the command to convert a string to an integer in Python?

A

int()

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

True or False: The ‘while’ loop will execute at least once.

A

False

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

What is the command to remove an item from a list in Python?

A

list.remove(item)

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

Fill in the blank: The command to sort a list in Python is ________.

A

list.sort()

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

What is the function used to find the maximum value in a list?

A

max()

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

What will the following command return? ‘Python’.lower()

A

‘python’

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

Multiple choice: Which of the following methods can be used to add an item to a list? A) append() B) add() C) insert()

A

A) append() and C) insert()

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

What is the command to create a tuple in Python?

23
Q

What is the purpose of the ‘return’ statement in a function?

A

To exit the function and optionally pass an expression back to the caller.

24
Q

True or False: Strings in Python are mutable.

25
What is the command to get the current working directory in Python?
import os; os.getcwd()
26
Fill in the blank: The command to create a set in Python is ________.
set()
27
What command is used to print output in Python?
The 'print()' function.
28
Fill in the blank: To create a list in Python, you use ________.
square brackets []
29
True or False: The 'len()' function returns the number of items in an object.
True
30
What is the command to create a new dictionary in Python?
'my_dict = {}' or 'my_dict = dict()'
31
Which command is used to read a file in Python?
'open()' function.
32
What is the output of 'print(type(5))'?
33
Choose the correct syntax to create a function in Python.
def function_name(parameters):
34
What command would you use to iterate over a list?
'for item in list:'
35
Fill in the blank: To convert a string to an integer, use ________.
'int()'
36
True or False: Lists in Python are immutable.
False
37
What is the command to import a module in Python?
'import module_name'
38
What is the purpose of the 'if __name__ == "__main__":' statement?
To allow or prevent parts of code from being run when the modules are imported.
39
Which command is used to add an item to a list?
'list.append(item)'
40
What does the 'range()' function do?
Generates a sequence of numbers.
41
Fill in the blank: The command to handle exceptions is ________.
'try-except'
42
True or False: A tuple can be modified after creation.
False
43
What command would you use to remove an item from a dictionary?
'del my_dict[key]'
44
What is the syntax to define a class in Python?
class ClassName:
45
Choose the correct command to sort a list in Python.
'list.sort()'
46
What is the command to get the current working directory?
'os.getcwd()'
47
Fill in the blank: To create a set in Python, you use ________.
curly braces {} or 'set()'
48
What does the 'map()' function do?
Applies a function to all items in an iterable.
49
True or False: The 'filter()' function returns an iterator.
True
50
What command would you use to create a virtual environment?
'python -m venv env_name'
51
Fill in the blank: To concatenate two strings, use ________.
'+' operator.
52
What is the command to check if a key exists in a dictionary?
'key in my_dict'
53
What is the output of 'print(3 ** 2)'?
9