1๏ธโฃ What is a string in Python?
Answer: A string is a sequence of characters enclosed in quotes (single, double, or triple).
Example: "Hello", 'World', '''Multi-line'''
2๏ธโฃ How do you reverse a string in Python?
Answer:
text = "hello"
reversed_text = text[::-1]
3๏ธโฃ Whatโs the difference between is and ==?
Answer:
โข == checks if values are equal
โข is checks if they are the same object in memory
4๏ธโฃ How do for and while loops differ?
Answer:
โข for loop is used for iterating over a sequence (list, string, etc.)
โข while loop runs as long as a condition is True
5๏ธโฃ What is the use of break, continue, and pass?
Answer:
โข break: exits the loop
โข continue: skips current iteration
โข pass: does nothing (placeholder)
6๏ธโฃ How to check if a substring exists in a string?
Answer:
"data" in "data science" # Returns True
7๏ธโฃ How do you use if-else conditions?
Answer:
x = 10
if x > 0:
print("Positive")
else:
print("Non-positive")
8๏ธโฃ What are f-strings in Python?
Answer: Introduced in Python 3.6 for cleaner string formatting:
name = "Riya"
print(f"Hello, {name}")
9๏ธโฃ How do you count characters or words in a string?
Answer:
text.count('a') # Count 'a'
len(text.split()) # Count words
๐ What is a nested loop?
Answer: A loop inside another loop:
for i in range(2):
for j in range(3):
print(i, j)
๐ฌ Tap โค๏ธ for more!