String Manipulation

Practicing operations and methods for manipulating strings.

1

How do you find the length of a string?

text = "Hello, World!"
length = len(text)
print(length)  # Output: 13

2

How do you convert a string to uppercase?

text = "hello"
upper_text = text.upper()
print(upper_text)  # Output: HELLO

3

How do you convert a string to lowercase?

text = "HELLO"
lower_text = text.lower()
print(lower_text)  # Output: hello

4

How do you capitalize the first letter of a string?


5

How do you split a string into a list?


6

How do you join a list of strings into a single string?


7

How do you check if a string contains a substring?


8

How do you find the index of a substring in a string?


9

How do you replace a substring with another substring?


10

How do you remove leading and trailing whitespace from a string?


11

How do you check if a string starts with a specific substring?


12

How do you check if a string ends with a specific substring?


13

How do you remove all instances of a substring from a string?


14

How do you count the number of occurrences of a substring in a string?


15

How do you convert a string into a list of characters?


16

How do you find all occurrences of a substring and their positions?


17

How do you pad a string with leading characters?


18

How do you align a string to the center with padding?


19

How do you strip only leading whitespace from a string?


20

How do you strip only trailing whitespace from a string?


21

How do you reverse a string?


22

How do you repeat a string multiple times?


23

How do you convert a string to a list of words?


24

How do you check if a string is numeric?


25

How do you check if all characters in a string are alphanumeric?


Last updated