Verified Solutions
What happens when you use `while True:` in a loop?
✔✔It creates an infinite loop that will keep running until it encounters a `break` statement or the
program is manually stopped.
How do you skip an iteration in a loop without breaking it?
✔✔You can use the `continue` statement to skip the current iteration and move to the next one.
What is the output of the following code:
```python
x = [10, 20, 30]
for num in x:
if num == 20:
break
print(num)
```
✔✔The output will be `10`, as the loop breaks when it encounters `20`.
1
, How do you find the length of a string in Python?
✔✔You can use the `len()` function, like `len("hello")`, which will return `5`.
What is the difference between `for` and `while` loops in Python?
✔✔A `for` loop iterates over a sequence (like a list or range), while a `while` loop continues
until a condition becomes `False`.
How can you iterate through the characters of a string?
✔✔You can use a `for` loop:
```python
for char in "hello":
print(char)
```
What will the following code print?
```python
x=5
2