0% found this document useful (0 votes)
23 views5 pages

Python Strings Worksheet Answer Key

This document is a worksheet for Grade 11 students focusing on Python strings. It includes theoretical questions, fill-in-the-blank exercises, code output examples, and practical coding tasks related to string manipulation in Python. Key concepts covered include string indexing, slicing, methods like `len()`, `lower()`, and string formatting.

Uploaded by

nandiniiphs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Python Strings Worksheet Answer Key

This document is a worksheet for Grade 11 students focusing on Python strings. It includes theoretical questions, fill-in-the-blank exercises, code output examples, and practical coding tasks related to string manipulation in Python. Key concepts covered include string indexing, slicing, methods like `len()`, `lower()`, and string formatting.

Uploaded by

nandiniiphs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

**Answer Key: Python Strings - Worksheet for Grade 11**

---

### SECTION A: THEORY (Short Answer)

1. **What is a string in Python?**

A string is a sequence of characters enclosed in single, double, or triple quotes.

2. **What is the difference between indexing and slicing in strings?**

Indexing accesses a single character using its position, while slicing retrieves a substring using a

range of indices.

3. **What is the purpose of escape characters? Give two examples.**

Escape characters allow special characters to be included in strings.

Examples: `\n` for newline, `\t` for tab.

4. **What does the `len()` function do?**

It returns the number of characters in a string.

5. **What will be the output of: `"Hello".upper()`?**

`"HELLO"`

---

### SECTION B: FILL IN THE BLANKS


1. The method `lower()` is used to convert all characters to lowercase.

2. The method `strip()` removes whitespace from both ends of a string.

3. The method `find()` returns the index of the first occurrence of a substring.

4. `join()` is used to join a list of strings into a single string.

5. `endswith()` checks if a string ends with a particular substring.

---

### SECTION C: CODE OUTPUT

```python

text = "Python Programming"

print(text[0:6])

```

**Output:** `Python`

```python

word = "banana"

print([Link]("a"))

```

**Output:** `3`

```python

s = " Hello World "

print([Link]())
```

**Output:** `Hello World`

```python

msg = "welcome"

print([Link]())

```

**Output:** `Welcome`

```python

sentence = "python is fun"

print([Link]())

```

**Output:** `Python Is Fun`

---

### SECTION D: PRACTICAL CODING

1. **Create a string "Hello, World!" and print its length.**

```python

s = "Hello, World!"

print(len(s))
```

2. **Convert the string "Computer Science" to lowercase and print it.**

```python

subject = "Computer Science"

print([Link]())

```

3. **Replace "bad" with "good" in the string "Python is not bad".**

```python

sentence = "Python is not bad"

print([Link]("bad", "good"))

```

4. **Check if the string "python123" is alphanumeric.**

```python

value = "python123"

print([Link]())

```

5. **Split the string "apple,banana,mango" by commas and print the list.**

```python

fruits = "apple,banana,mango"
print([Link](","))

```

You might also like