Strings Unit 2 Flashcards
(10 cards)
What is a string in programming?
A string is a sequence of characters, like letters, numbers, or symbols, enclosed in quotes.
What does the index value of a string character represent?
It represents the position of each character in the string, starting from 0.
What function is used to find the number of characters in a string?
The built-in length function, e.g. len(string) in Python.
What is string traversal?
String traversal is using a loop to go through a string character by character.
What is iteration in the context of strings?
Iteration is repeating an action for each character in a string using a loop.
How do you traverse a string using a loop in Python?
for char in string:
print(char)
What is string concatenation?
It is the process of joining two or more strings together.
Example: “Hello” + “ “ + “World” → “Hello World”
What is string slicing?
Extracting a part of a string using its index values.
Example: text[0:4] → returns characters from index 0 to 3.
What is string splitting?
Breaking a string into a list of parts using a separator.
Example: “a,b,c”.split(“,”) → [‘a’, ‘b’, ‘c’]
What is string formatting?
Controlling how text is displayed, such as inserting variables into a string.
Example: f”Hello, {name}!”