Q: What is a string in Python?
A: A string is a sequence of characters enclosed in quotes.
Q: How can you create a string in Python?
A: You can create a string by enclosing characters in either single quotes ('') or double quotes (“”).
Q: How can you access individual characters in a string?
A: You can access individual characters in a string using indexing, starting from 0.
Q: How can you find the length of a string?
A: You can find the length of a string using the len() function.
Q: Can you modify a specific character in a string?
A: No, strings in Python are immutable, which means you cannot modify individual characters. You need to create a new string.
Q: How can you concatenate two strings?
A: You can concatenate two strings using the + operator.
Q: What is string interpolation in Python?
A: String interpolation is a way to embed variables within a string by using the f-string syntax, like f“Hello, {name}!”.
Q: How can you convert a string to uppercase in Python?
A: You can convert a string to uppercase using the upper() method.
Q: How can you convert a string to lowercase in Python?
A: You can convert a string to lowercase using the lower() method.
Q: How can you check if a string starts with a specific substring?
A: You can use the startswith() method to check if a string starts with a specific substring.
Q: How can you check if a string ends with a specific substring?
A: You can use the endswith() method to check if a string ends with a specific substring.
Q: How can you split a string into a list of substrings?
A: You can use the split() method to split a string into a list of substrings based on a delimiter.
Q: How can you join a list of strings into a single string?
A: You can use the join() method to join a list of strings into a single string using a specified delimiter.
Q: How can you remove leading and trailing whitespace from a string?
A: You can use the strip() method to remove leading and trailing whitespace from a string.
Q: How can you replace a specific substring in a string with another substring?
A: You can use the replace() method to replace a specific substring in a string with another substring.
Q: How can you check if a character is present in a string?
A: You can use the in operator to check if a character is present in a string.
Q: How can you find the index of the first occurrence of a substring in a string?
A: You can use the index() method to find the index of the first occurrence of a substring in a string.
Q: How can you count the number of occurrences of a substring in a string?
A: You can use the count() method to count the number of occurrences of a substring in a string.
Q: How can you reverse a string in Python?
A: You can use string slicing with a step of -1 to reverse a string.
Q: How can you check if a string contains only numeric characters?
A: You can use the isdigit() method to check if a string contains only numeric characters.