Beginner Flashcards

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 statically typed 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 a sequence of characters enclosed in quotes.

A

string

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 mutable data type in Python? (a) Tuple (b) List (c) String

A

b) List

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

What is the output of the expression 3 * ‘hello’?

A

‘hellohellohello’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
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
8
Q

What is the purpose of the ‘self’ keyword in Python class methods?

A

It refers to the instance of the class.

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

What built-in function can be used to get the length of a list?

A

len()

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

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

A

<class ‘list’>

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

Which symbol is used for comments in Python?

A

#

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

What does the ‘pass’ statement do in Python?

A

It is a null statement; it does nothing.

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

What are the two main types of loops in Python?

A

for loop and while loop

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

What is a dictionary in Python?

A

A collection of key-value pairs.

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

True or False: Python supports multiple inheritance.

A

True

Multiple inheritance is a feature in Python that allows a class to inherit from more than one parent class. This means a child class can derive attributes and methods from multiple base classes.

Eg.

class Child(Parent1, Parent2):

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

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

A

To include external modules or libraries.

17
Q

Which method is used to add an element to the end of a list?

18
Q

What is the difference between ‘==’ and ‘is’ in Python?

A

’==’ checks for value equality, ‘is’ checks for identity.

19
Q

What will be the output of the expression 5 // 2?

And what is the operator?

A

2

// is the floor division operator, it divides the left by the right and rounds the answer down to the nearest integer, discarding the decimal

20
Q

What is a lambda function in Python?

A

An anonymous function defined with the lambda keyword.

21
Q

What function is used to read input from the user in Python?

22
Q

What is list comprehension in Python?

A

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

It allows you to create a new list by applying an an expression to each element in a list using an interable

Eg:

Squared = [2 ** x for x in numbers]

23
Q

What does the ‘break’ statement do in a loop?

A

It exits the loop immediately.

24
Q

What is the purpose of the ‘try’ and ‘except’ blocks in Python?

A

To handle exceptions and errors.

25
Which function is used to convert a string to an integer in Python?
int()
26
What is the difference between a list and a tuple in Python?
A list is mutable, while a tuple is immutable.
27
What does the 'with' statement do in Python?
It simplifies exception handling by encapsulating common preparation and cleanup tasks.
28
What is a generator expression?
A compact, high-performance construct for generating values on the fly. Similar to list comprehension but instead of creating an entire list at once, it yields them one at a time, which is processed sequentially. Therefore generator expressions are more memory-efficient, which is particularly helpful for large data sets or streams of data. Enclosed in parenthesis instead of square brackets Often used with functions like sum(), min(), max() and join()