Python Basics, Conditionals, and Loops Flashcards

1
Q

What are the three types of quotes you can use for strings in Python?

A

Single (‘ ‘), Double (“ “), and Triple (‘’’ ‘’’ or “”” “””).

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

When should you use triple quotes for strings?

A

When the string contains both single and double quotes.

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

How do you print numerical values in Python?

A

Using print(), optionally converting numbers to strings using str().

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

What does print(‘The value of x is: ‘ + str(5.5)) output?

A

The value of x is: 5.5

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

What are some common data types in Python?

A

Integers, floats, characters, strings, and Boolean values.

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

What is an f-string, and how is it used?

A

An f-string allows embedding variables directly in a string using {}. Example:
name = “Alice”
print(f”Hello, {name}!”)

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

What does // do in Python?

A

It performs integer division, discarding the decimal part.

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

What does % do in Python?

A

It finds the remainder of a division.

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

What does ** do in Python?

A

It calculates exponents (e.g., 2 ** 3 equals 8).

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

How do you convert a float to an integer?

A

Using int(). Example: int(5.5) returns 5.

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

How do you convert an integer to a float?

A

Using float(). Example: float(2) returns 2.0.

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

What function is used to get user input in Python?

A

name = input(“Enter your name: “)
print(name)

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

What is an if statement?

A

A control structure that runs a block of code if a condition is True.

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

What is the difference between if and elif?

A

if checks the first condition, and elif checks additional conditions if the previous ones were False.

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

What does != do in Python?

A

It checks if two values are not equal.

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

What does and do in Python?

A

It returns True only if both conditions are True.

17
Q

What does or do in Python?

A

It returns True if at least one of the conditions is True.

18
Q

What are the two types of loops in Python?

A

while loops and for loops.

19
Q

When should you use a while loop?

A

When the number of repetitions is unknown, and you repeat until a condition is met.

20
Q

When should you use a for loop?

A

When looping over a known range

21
Q

What does range(5) do in a for loop?

A

It generates numbers from 0 to 4.

22
Q

What does break do in a loop?

A

It immediately exits the loop.

23
Q

What does continue do in a loop?

A

It skips the current iteration and moves to the next one.