|  | 
|  | 1 | +# Python for Beginners — Day 2 Assignment | 
|  | 2 | + | 
|  | 3 | +**Prepared by:** [Shubham](https://github.com/Shubham-S151)  | 
|  | 4 | +🎥 *From the [Bit and Pi](https://www.youtube.com/@BitandPi) YouTube Channel* | 
|  | 5 | + | 
|  | 6 | +--- | 
|  | 7 | + | 
|  | 8 | +## Topics Covered Today | 
|  | 9 | + | 
|  | 10 | +- What is a String in Python? | 
|  | 11 | +- Creating Strings | 
|  | 12 | +- Basic String Operations | 
|  | 13 | +- Indexing and Slicing | 
|  | 14 | +- String Methods | 
|  | 15 | +- String Formatting | 
|  | 16 | +- Escape Characters and Raw Strings | 
|  | 17 | + | 
|  | 18 | +--- | 
|  | 19 | + | 
|  | 20 | +## Assignment Instructions | 
|  | 21 | + | 
|  | 22 | +- Complete the questions below in a Python file or a Jupyter notebook. | 
|  | 23 | +- Submit your work as `.py`, `.ipynb`, or `.pdf` format. | 
|  | 24 | +- Try to write comments in your code to explain your logic. | 
|  | 25 | + | 
|  | 26 | +--- | 
|  | 27 | + | 
|  | 28 | +## Part A — Theory Questions | 
|  | 29 | + | 
|  | 30 | +Answer the following in brief (1–2 lines each): | 
|  | 31 | + | 
|  | 32 | +1. What is a string in Python? How is it different from a character in C? | 
|  | 33 | +2. Are strings mutable in Python? Explain with an example. | 
|  | 34 | +3. What is the difference between `.find()` and `.index()` methods? | 
|  | 35 | +4. What are raw strings? Give an example. | 
|  | 36 | +5. What are f-strings and why are they useful? | 
|  | 37 | + | 
|  | 38 | +--- | 
|  | 39 | + | 
|  | 40 | +## Part B — Coding Exercises | 
|  | 41 | + | 
|  | 42 | +### 1. **String Creation** | 
|  | 43 | + | 
|  | 44 | +- Create 3 different strings using: | 
|  | 45 | + - Single quotes | 
|  | 46 | + - Double quotes | 
|  | 47 | + - Triple quotes (multiline) | 
|  | 48 | + | 
|  | 49 | +### 2. **Concatenation and Repetition** | 
|  | 50 | + | 
|  | 51 | +- Concatenate two strings: `"Hello"` and `"World"`  | 
|  | 52 | +- Repeat the string `"ha"` 4 times | 
|  | 53 | + | 
|  | 54 | +### 3. **String Indexing and Slicing** | 
|  | 55 | + | 
|  | 56 | +Given `s = "Python Programming"`: | 
|  | 57 | + | 
|  | 58 | +- Print the first character | 
|  | 59 | +- Print the last character | 
|  | 60 | +- Slice `"Python"` from the string | 
|  | 61 | +- Print the string in reverse | 
|  | 62 | +- Print every second character | 
|  | 63 | + | 
|  | 64 | +### 4. **Using String Methods** | 
|  | 65 | + | 
|  | 66 | +Given `text = " Learn Python Programming "`: | 
|  | 67 | + | 
|  | 68 | +- Convert the text to lowercase | 
|  | 69 | +- Remove extra spaces from both sides | 
|  | 70 | +- Replace `"Python"` with `"C++"` | 
|  | 71 | +- Count how many times `"a"` appears | 
|  | 72 | + | 
|  | 73 | +### 5. **Splitting and Joining** | 
|  | 74 | + | 
|  | 75 | +Given: `sentence = "Python is easy to learn"` | 
|  | 76 | + | 
|  | 77 | +- Split the sentence into a list of words | 
|  | 78 | +- Join the list back into a single string using `-` as a separator | 
|  | 79 | + | 
|  | 80 | +### 6. **String Formatting** | 
|  | 81 | + | 
|  | 82 | +- Use all 3 string formatting methods (`f-string`, `.format()`, and `%`) to print:  | 
|  | 83 | + `"Hello, my name is Alex and I am 30 years old."` | 
|  | 84 | + | 
|  | 85 | +### 7. **Escape Characters** | 
|  | 86 | + | 
|  | 87 | +- Print: | 
|  | 88 | +```bash | 
|  | 89 | +Name: Alice | 
|  | 90 | +Age: 25 | 
|  | 91 | +Location: New York\tUSA | 
|  | 92 | +``` | 
|  | 93 | + | 
|  | 94 | +### To Acess the solution visit : [Click_here](https://gist.github.com/Bit-and-Pi/3a86f0a405fa583644403dcbf06a7591) | 
0 commit comments