Strings - AP Computer Science Principles

  1. What method finds a substring's first occurrence in Python?
    find(). Locates initial position of substring occurrence.
  2. What method converts a string to uppercase in JavaScript?
    toUpperCase(). Converts all letters to uppercase format.
  3. Identify the function that checks if a character is a digit in Python.
    isdigit(). Returns True if character is numeric digit.
  4. Identify the method to capitalize the first character of a string in Python.
    capitalize(). Makes first letter uppercase, rest lowercase.
  5. What method checks if a string contains a specific substring in JavaScript?
    includes(). Checks if substring exists within the string.
  6. Identify the method to encode a string to UTF-8 in Python.
    encode('utf-8'). Converts string to UTF-8 byte encoding.
  7. What function converts a string to a float in Python?
    float(). Converts string to decimal number format.
  8. What function converts a string to a list of characters in Python?
    list(). Creates list with each character as element.
  9. What function converts an integer to a string in JavaScript?
    toString(). Converts numeric value to string representation.
  10. Identify the method to convert a string to lowercase in Java.
    toLowerCase(). Built-in method for case conversion in Java.
  11. State the method to check if a string is empty in JavaScript.
    length property or === ''. Tests length property or compares to empty.
  12. What function returns the length of a string in most programming languages?
    length() or len(). Standard method to count characters in a string.
  13. What method converts a string to a float in JavaScript?
    parseFloat(). Converts string to floating-point number.
  14. State the method to get the character at a specific index in C++.
    at() or []. Accesses individual character by position.
  15. What method converts a string to uppercase in Python?
    upper(). Transforms all letters to capital case.
  16. Which method checks the equality of two strings in Java?
    equals(). Compares string content for exact match.
  17. Identify the method to find the index of a character in a string in Java.
    indexOf(). Returns position of first occurrence of character.
  18. What method centers a string with a specified width in Python?
    center(). Pads string with spaces for centered alignment.
  19. State the method to check if a string ends with a specific sequence in Java.
    endsWith(). Tests if string terminates with given suffix.
  20. Which method gets a substring from a string in JavaScript?
    substring(). Extracts portion of string between indices.
  21. Which method checks if a string contains only whitespace in Python?
    isspace(). Checks if all characters are whitespace.
  22. Identify the method to find a substring's last occurrence in Java.
    lastIndexOf(). Finds rightmost position of substring match.
  23. Find and correct the error: 'Java'.charAt(2) in Python.
    Correct: 'Java'[2]. Python uses bracket notation for character access.
  24. What function converts a string to an integer in Python?
    int(). Parses string representation into integer value.
  25. Which function creates a string from a list of characters in Python?
    join(). Combines list elements into single string.
  26. Which method checks if a string starts with a specific sequence in Python?
    startswith(). Tests if string begins with given prefix.
  27. Which method can reverse a string in Python?
    slice with [::-1]. Extended slicing with step -1 reverses order.
  28. What method converts a string to a list of words in Python?
    split(). Breaks string into word array elements.
  29. Which method splits a string into an array in Python?
    split(). Divides string into array elements by delimiter.
  30. Identify the method that formats a string in Python.
    format(). Inserts values into string template placeholders.
  31. State the method to compare two strings lexicographically in Java.
    compareTo(). Performs alphabetical ordering comparison between strings.
  32. Find and correct the error: 'Hello'.substring(0, 3) in Python.
    Correct: 'Hello'[0:3]. Python uses slice notation instead of substring method.
  33. Which method concatenates two strings in Python?
    The + operator. Joins strings together using addition operator.
  34. Which method checks if a string is made of alphabetic characters in Python?
    isalpha(). Validates string contains only letter characters.
  35. State the method to replace a substring in a string in Java.
    replace(). Substitutes specified text with new text.
  36. Find and correct the error: 'Hello'.indexOf('e') in Python.
    Correct: 'Hello'.find('e'). Python uses find() instead of indexOf().
  37. Which method trims whitespace from both ends of a string in Python?
    strip(). Removes leading and trailing whitespace characters.

Study these flashcards