0% found this document useful (0 votes)
0 views

String_Operators_Practice

The document explains Python string operators, specifically concatenation using the '+' operator and replication using the '*' operator, with examples provided. It includes practice questions at various levels, testing the user's understanding of these concepts through concatenation and repetition tasks. Additionally, there are creative tasks and a bonus challenge to further apply the learned skills.

Uploaded by

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

String_Operators_Practice

The document explains Python string operators, specifically concatenation using the '+' operator and replication using the '*' operator, with examples provided. It includes practice questions at various levels, testing the user's understanding of these concepts through concatenation and repetition tasks. Additionally, there are creative tasks and a bonus challenge to further apply the learned skills.

Uploaded by

binduann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python String Operators: Concatenation

and Replication
1. Explanation
➤ Concatenation (+ operator): Used to join two or more strings.

Example:
str1 = "Hello"
str2 = "World"
result = str1 + " " + str2
Output: Hello World

➤ Replication (* operator): Used to repeat a string multiple times.

Example:
text = "Hi! "
result = text * 3
Output: Hi! Hi! Hi!

2. Practice Questions with Answers

Level 1: Basic Practice


1. Concatenate two strings:
str1 = "Good"
str2 = "Morning"
Answer: Good Morning

2. Repeat a string 4 times:


str1 = "Bye! "
Answer: Bye! Bye! Bye! Bye!

3. Concatenate first name and last name:


first = "Alice"
last = "Johnson"
Answer: Alice Johnson

Level 2: Apply & Output Prediction


4. Output of print("Python" + "3")
Answer: Python3
5. Output of print("Go! " * 5)
Answer: Go! Go! Go! Go! Go!

6. Fix the error:


age = 15
print("My age is " + age)
Answer: print("My age is " + str(age))

Level 3: Creative Tasks


7. Create a pattern:
Answer:
HelloHelloHello
WorldWorld

8. Form a sentence:
Input: name = "Liam", hobby = "painting"
Answer: Hello Liam! I heard you like painting.

Bonus Challenge
9. Repeat name with dashes:
Input: Arya
Answer: Arya-Arya-Arya

10. Repeat word by number:


Input: Hi, 4
Answer: HiHiHiHi

You might also like