Strings - AP Computer Science Principles
Card 1 of 30
What function returns the length of a string in most programming languages?
What function returns the length of a string in most programming languages?
Tap to reveal answer
length() or len(). Standard method to count characters in a string.
length() or len(). Standard method to count characters in a string.
← Didn't Know|Knew It →
Which method checks if a string contains only whitespace in Python?
Which method checks if a string contains only whitespace in Python?
Tap to reveal answer
isspace(). Checks if all characters are whitespace.
isspace(). Checks if all characters are whitespace.
← Didn't Know|Knew It →
Identify the method to capitalize the first character of a string in Python.
Identify the method to capitalize the first character of a string in Python.
Tap to reveal answer
capitalize(). Makes first letter uppercase, rest lowercase.
capitalize(). Makes first letter uppercase, rest lowercase.
← Didn't Know|Knew It →
State the method to compare two strings lexicographically in Java.
State the method to compare two strings lexicographically in Java.
Tap to reveal answer
compareTo(). Performs alphabetical ordering comparison between strings.
compareTo(). Performs alphabetical ordering comparison between strings.
← Didn't Know|Knew It →
Which function creates a string from a list of characters in Python?
Which function creates a string from a list of characters in Python?
Tap to reveal answer
join(). Combines list elements into single string.
join(). Combines list elements into single string.
← Didn't Know|Knew It →
What function converts a string to a float in Python?
What function converts a string to a float in Python?
Tap to reveal answer
float(). Converts string to decimal number format.
float(). Converts string to decimal number format.
← Didn't Know|Knew It →
Which method checks if a string is made of alphabetic characters in Python?
Which method checks if a string is made of alphabetic characters in Python?
Tap to reveal answer
isalpha(). Validates string contains only letter characters.
isalpha(). Validates string contains only letter characters.
← Didn't Know|Knew It →
Identify the function that checks if a character is a digit in Python.
Identify the function that checks if a character is a digit in Python.
Tap to reveal answer
isdigit(). Returns True if character is numeric digit.
isdigit(). Returns True if character is numeric digit.
← Didn't Know|Knew It →
What function converts an integer to a string in JavaScript?
What function converts an integer to a string in JavaScript?
Tap to reveal answer
toString(). Converts numeric value to string representation.
toString(). Converts numeric value to string representation.
← Didn't Know|Knew It →
Which method checks the equality of two strings in Java?
Which method checks the equality of two strings in Java?
Tap to reveal answer
equals(). Compares string content for exact match.
equals(). Compares string content for exact match.
← Didn't Know|Knew It →
Identify the method that formats a string in Python.
Identify the method that formats a string in Python.
Tap to reveal answer
format(). Inserts values into string template placeholders.
format(). Inserts values into string template placeholders.
← Didn't Know|Knew It →
What function converts a string to a list of characters in Python?
What function converts a string to a list of characters in Python?
Tap to reveal answer
list(). Creates list with each character as element.
list(). Creates list with each character as element.
← Didn't Know|Knew It →
Which method can reverse a string in Python?
Which method can reverse a string in Python?
Tap to reveal answer
slice with [::-1]. Extended slicing with step -1 reverses order.
slice with [::-1]. Extended slicing with step -1 reverses order.
← Didn't Know|Knew It →
State the method to check if a string ends with a specific sequence in Java.
State the method to check if a string ends with a specific sequence in Java.
Tap to reveal answer
endsWith(). Tests if string terminates with given suffix.
endsWith(). Tests if string terminates with given suffix.
← Didn't Know|Knew It →
Which method trims whitespace from both ends of a string in Python?
Which method trims whitespace from both ends of a string in Python?
Tap to reveal answer
strip(). Removes leading and trailing whitespace characters.
strip(). Removes leading and trailing whitespace characters.
← Didn't Know|Knew It →
State the method to get the character at a specific index in C++.
State the method to get the character at a specific index in C++.
Tap to reveal answer
at() or []. Accesses individual character by position.
at() or []. Accesses individual character by position.
← Didn't Know|Knew It →
State the method to replace a substring in a string in Java.
State the method to replace a substring in a string in Java.
Tap to reveal answer
replace(). Substitutes specified text with new text.
replace(). Substitutes specified text with new text.
← Didn't Know|Knew It →
Find and correct the error: 'Hello'.substring(0, 3) in Python.
Find and correct the error: 'Hello'.substring(0, 3) in Python.
Tap to reveal answer
Correct: 'Hello'[0:3]. Python uses slice notation instead of substring method.
Correct: 'Hello'[0:3]. Python uses slice notation instead of substring method.
← Didn't Know|Knew It →
Which method splits a string into an array in Python?
Which method splits a string into an array in Python?
Tap to reveal answer
split(). Divides string into array elements by delimiter.
split(). Divides string into array elements by delimiter.
← Didn't Know|Knew It →
What method checks if a string contains a specific substring in JavaScript?
What method checks if a string contains a specific substring in JavaScript?
Tap to reveal answer
includes(). Checks if substring exists within the string.
includes(). Checks if substring exists within the string.
← Didn't Know|Knew It →
What method centers a string with a specified width in Python?
What method centers a string with a specified width in Python?
Tap to reveal answer
center(). Pads string with spaces for centered alignment.
center(). Pads string with spaces for centered alignment.
← Didn't Know|Knew It →
Which method gets a substring from a string in JavaScript?
Which method gets a substring from a string in JavaScript?
Tap to reveal answer
substring(). Extracts portion of string between indices.
substring(). Extracts portion of string between indices.
← Didn't Know|Knew It →
Identify the method to encode a string to UTF-8 in Python.
Identify the method to encode a string to UTF-8 in Python.
Tap to reveal answer
encode('utf-8'). Converts string to UTF-8 byte encoding.
encode('utf-8'). Converts string to UTF-8 byte encoding.
← Didn't Know|Knew It →
What method converts a string to a list of words in Python?
What method converts a string to a list of words in Python?
Tap to reveal answer
split(). Breaks string into word array elements.
split(). Breaks string into word array elements.
← Didn't Know|Knew It →
State the method to check if a string is empty in JavaScript.
State the method to check if a string is empty in JavaScript.
Tap to reveal answer
length property or === ''. Tests length property or compares to empty.
length property or === ''. Tests length property or compares to empty.
← Didn't Know|Knew It →
Find and correct the error: 'Hello'.indexOf('e') in Python.
Find and correct the error: 'Hello'.indexOf('e') in Python.
Tap to reveal answer
Correct: 'Hello'.find('e'). Python uses find() instead of indexOf().
Correct: 'Hello'.find('e'). Python uses find() instead of indexOf().
← Didn't Know|Knew It →
Identify the method to convert a string to lowercase in Java.
Identify the method to convert a string to lowercase in Java.
Tap to reveal answer
toLowerCase(). Built-in method for case conversion in Java.
toLowerCase(). Built-in method for case conversion in Java.
← Didn't Know|Knew It →
Which method concatenates two strings in Python?
Which method concatenates two strings in Python?
Tap to reveal answer
The + operator. Joins strings together using addition operator.
The + operator. Joins strings together using addition operator.
← Didn't Know|Knew It →
State the method to replace a substring in a string in Java.
State the method to replace a substring in a string in Java.
Tap to reveal answer
replace(). Substitutes specified text with new text.
replace(). Substitutes specified text with new text.
← Didn't Know|Knew It →
What function returns the length of a string in most programming languages?
What function returns the length of a string in most programming languages?
Tap to reveal answer
length() or len(). Standard method to count characters in a string.
length() or len(). Standard method to count characters in a string.
← Didn't Know|Knew It →