Python fundamentals Flashcards

(27 cards)

1
Q

Define variable in Python.

A

A storage location identified by a name that holds a value.

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

What keyword is used to define a function?

A

The keyword ‘def’ is used to define a function.

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

True or false: Lists are immutable in Python.

A

FALSE

Lists can be modified after creation.

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

Fill in the blank: A tuple is defined using _______ parentheses.

A

Round

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

What does PEP stand for in Python?

A

Python Enhancement Proposal.

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

Define dictionary in Python.

A

A collection of key-value pairs, where each key is unique.

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

What is the purpose of the if statement?

A

To execute a block of code conditionally based on a boolean expression.

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

True or false: Strings can be modified in Python.

A

FALSE

Strings are immutable; any modification creates a new string.

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

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

A

8, as it calculates 2 raised to the power of 3.

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

Fill in the blank: A loop is used for _______ over a sequence.

A

Iterating

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

What does the len() function do?

A

It returns the number of items in an object.

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

Define list comprehension.

A

A concise way to create lists using a single line of code.

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

What is the purpose of the return statement?

A

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

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

True or false: Comments in Python start with #.

A

TRUE

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

What is a module in Python?

A

A file containing Python code that can be imported and used in other programs.

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

Fill in the blank: The input() function is used to _______ user input.

17
Q

What is the purpose of the with statement?

A

To wrap the execution of a block with methods defined by a context manager.

18
Q

Define exception handling.

A

The process of responding to the occurrence of exceptions during program execution.

19
Q

What does the break statement do in a loop?

A

It terminates the loop and transfers control to the statement following the loop.

20
Q

True or false: Sets can contain duplicate elements.

A

FALSE

Sets automatically remove duplicates.

21
Q

What is the purpose of the pass statement?

A

To act as a placeholder in code where no action is required.

22
Q

Fill in the blank: A class is a blueprint for creating _______ in Python.

23
Q

What is the output of print(type([]))?

A

<class ‘list’>, indicating that the object is a list.

24
Q

Define lambda function.

A

An anonymous function defined with the keyword ‘lambda’.

25
What does **import** do in Python?
It allows you to include the functionality of another module in your code.
26
True or false: **Python** is a compiled language.
FALSE ## Footnote Python is primarily an interpreted language.
27
Fill in the blank: The **self** parameter in methods refers to _______ instance.
The current