Crack the Code: Easy Python Strings Quiz! Quiz

  1. Definition and Types

    Which of the following is a correct way to define a string in Python?

    1. 'hello'
    2. {hello}
    3. [hello]
    4. u003Chellou003E
    5. |hello|
  2. String Immutability

    What does it mean when we say Python strings are immutable?

    1. Their value cannot be changed after creation
    2. They can only hold numbers
    3. They are stored in capital letters
    4. You cannot print them
    5. They must be defined with double quotes
  3. Quoting Styles

    Which type of quotes allows you to write a Python string that spans multiple lines?

    1. Triple quotes
    2. Single quotes
    3. Bracket quotes
    4. Tilted quotes
    5. Curly quotes
  4. String Concatenation

    What is the output of the following code: 'Hello' + ' ' + 'World'?

    1. Hello World
    2. HelloWorld
    3. 'Hello' + ' ' + 'World'
    4. Hello+World
    5. Hello, World
  5. Finding String Length

    Which function returns the length of a string in Python? For example, len('Python').

    1. len()
    2. size()
    3. count()
    4. length()
    5. strlengt()
  6. String Indexing

    If my_string = 'Code', what will my_string[0] return?

    1. C
    2. o
    3. d
    4. e
    5. Co
  7. String Slicing

    Given the string s = 'Python', what is the result of s[1:4]?

    1. yth
    2. Pyt
    3. hon
    4. ytho
    5. Pyth
  8. Changing Case

    Which method would you use to convert the string 'python' to 'PYTHON'?

    1. upper()
    2. capitalize()
    3. revcase()
    4. swapcase()
    5. lowercase()
  9. Whitespace Trimming

    If s = ' hello ', which method removes spaces from both ends and returns 'hello'?

    1. strip()
    2. split()
    3. remove()
    4. trim()
    5. erase()
  10. Formatted Strings

    How would you insert the value of a variable name into a string using an f-string? Example: name = 'Alex'.

    1. f'Hello, {name}!'
    2. 'Hello, %s!' % name
    3. 'Hello, ' + name +'!'
    4. format('Hello, {}!', name)
    5. F[{name}]