Basic Python Flashcards

(27 cards)

1
Q

What is the correct file extension for Python files?

A

.py

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

True or False: Python is a compiled language.

A

False

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

Fill in the blank: In Python, a _____ is used to store multiple items in a single variable.

A

list

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

What keyword is used to define a function in Python?

A

def

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

Which of the following is a valid variable name in Python? (a) 1variable (b) variable_1 (c) variable-1

A

b

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

What function would you use to get user input in Python?

A

input()

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

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

A

8

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

True or False: Python uses indentation to define blocks of code.

A

True

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

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

A

To execute a block of code conditionally.

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

What data type is used to represent a true or false value in Python?

A

bool

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

Fill in the blank: A _____ is a collection of key-value pairs in Python.

A

dictionary

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

What operator is used for equality comparison in Python?

A

==

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

Which of the following methods can be used to add an item to a list? (a) add() (b) append() (c) insert()

A

b and c

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

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

A

<class ‘int’>

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

True or False: A tuple is mutable.

A

False

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

What is the purpose of a loop in Python?

A

To execute a block of code repeatedly.

17
Q

What keyword is used to exit a loop prematurely?

18
Q

Fill in the blank: The _____ function is used to convert a string to an integer.

19
Q

What is the output of print(‘Hello’ + ‘ World’)?

20
Q

Which of the following is not a valid Python data type? (a) list (b) number (c) string

21
Q

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

A

To return a value from the function.

22
Q

What is the correct way to import a module in Python?

A

import module_name

23
Q

True or False: Python supports multiple inheritance.

24
Q

What does the ‘len()’ function do?

A

Returns the length of an object.

25
Fill in the blank: A _____ is an ordered collection of items in Python.
list
26
What is the output of print(10 // 3)?
3
27
What is the purpose of comments in Python code?
To provide explanations or notes for the code.