commands Flashcards

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
Q

What is the command to get the current working directory in Python?

A

import os; os.getcwd()

26
Q

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

27
Q

What command is used to print output in Python?

A

The ‘print()’ function.

28
Q

Fill in the blank: To create a list in Python, you use ________.

A

square brackets []

29
Q

True or False: The ‘len()’ function returns the number of items in an object.

30
Q

What is the command to create a new dictionary in Python?

A

‘my_dict = {}’ or ‘my_dict = dict()’

31
Q

Which command is used to read a file in Python?

A

‘open()’ function.

32
Q

What is the output of ‘print(type(5))’?

A

<class ‘int’>

33
Q

Choose the correct syntax to create a function in Python.

A

def function_name(parameters):

34
Q

What command would you use to iterate over a list?

A

‘for item in list:’

35
Q

Fill in the blank: To convert a string to an integer, use ________.

A

‘int()’

36
Q

True or False: Lists in Python are immutable.

37
Q

What is the command to import a module in Python?

A

‘import module_name’

38
Q

What is the purpose of the ‘if __name__ == “__main__”:’ statement?

A

To allow or prevent parts of code from being run when the modules are imported.

39
Q

Which command is used to add an item to a list?

A

‘list.append(item)’

40
Q

What does the ‘range()’ function do?

A

Generates a sequence of numbers.

41
Q

Fill in the blank: The command to handle exceptions is ________.

A

‘try-except’

42
Q

True or False: A tuple can be modified after creation.

43
Q

What command would you use to remove an item from a dictionary?

A

‘del my_dict[key]’

44
Q

What is the syntax to define a class in Python?

A

class ClassName:

45
Q

Choose the correct command to sort a list in Python.

A

‘list.sort()’

46
Q

What is the command to get the current working directory?

A

‘os.getcwd()’

47
Q

Fill in the blank: To create a set in Python, you use ________.

A

curly braces {} or ‘set()’

48
Q

What does the ‘map()’ function do?

A

Applies a function to all items in an iterable.

49
Q

True or False: The ‘filter()’ function returns an iterator.

50
Q

What command would you use to create a virtual environment?

A

‘python -m venv env_name’

51
Q

Fill in the blank: To concatenate two strings, use ________.

A

’+’ operator.

52
Q

What is the command to check if a key exists in a dictionary?

A

‘key in my_dict’

53
Q

What is the output of ‘print(3 ** 2)’?