✅ MODULE Il

0 0 0
                                        


📌 PART – A (2 MARKS EACH)

------------------------------------------

1. Define the use of decision-making statements.

Decision-making statements allow a program to choose different actions based on conditions.
Examples include: if, if-else, if-elif, and nested if.

---

2. Write the syntax of nested if statement.

if condition1:
    if condition2:
        statement

---

3. Write the syntax of if-elif ladder statement.

if condition1:
    statements
elif condition2:
    statements
else:
    statements

---

4. Explain the use of range() function.

range() generates a sequence of numbers and is mainly used in loops.
Forms:

range(stop)

range(start, stop)

range(start, stop, step)

---

5. List the Python loop control statements.

break

continue

pass

---

6. List the escape sequences.

→ new line

\t → tab

\' → single quote

\" → double quote

\\ → backslash

---

7. List any 4 string built-in methods.

upper()

lower()

split()

replace()

---

8. How to specify docstrings in python?

Using triple quotes inside a function.

def fun():
    """This is a docstring"""

---

9. Difference between re.search() and re.findall().

re.search() re.findall()

Returns first match Returns all matches
Returns match object Returns list

---

10. What is the use of curly braces in Python regular expressions?

Curly braces {} specify the number of repetitions.
Example: a{3} → matches "aaa".

---

11. Python program to extract email address using regex.

import re
text = "My mail is test123@gmail.com"
email = re.findall(r'\S+@\S+\.\S+', text)
print(email)

---

12. Python code to create a list with mixed data types.

l = [10, 3.5, "hello", True]

---

13. Differentiate IndexError and TypeError.

IndexError TypeError

python Where stories live. Discover now