0
0
Pythonprogramming~5 mins

String creation and representation in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are the three ways to create a string in Python?
You can create strings using single quotes ('example'), double quotes ("example"), or triple quotes ('''example''' or """example"""). Triple quotes allow multi-line strings.
Click to reveal answer
intermediate
How does Python represent strings internally?
Python stores strings as sequences of Unicode characters, allowing support for many languages and symbols beyond ASCII.
Click to reveal answer
intermediate
What is the difference between raw strings and normal strings in Python?
Raw strings (prefix r or R) treat backslashes (\) as literal characters and do not interpret escape sequences like \n or \t.
Click to reveal answer
beginner
How can you include quotes inside a string without ending it?
You can use different quotes to surround the string than the ones inside it, for example: "He said 'hello'" or 'She said "hi"'. Alternatively, use escape characters like \" or \'.
Click to reveal answer
intermediate
What does the repr() function do with strings?
repr() returns a string representation that shows the string with quotes and escape characters, useful for debugging.
Click to reveal answer
Which of these is a valid way to create a multi-line string in Python?
AUsing double quotes " only
BUsing single quotes ' only
CUsing triple quotes ''' or """
DUsing backticks `string`
What does the prefix r before a string mean in Python?
AIt creates a raw string where backslashes are treated literally
BIt reverses the string
CIt makes the string uppercase
DIt removes all spaces
How can you include a double quote inside a string defined with double quotes?
AUse single quotes inside double quotes without escape
BJust type it without any special character
CYou cannot include double quotes inside double quotes
DEscape it with a backslash like \"
What will repr('Hello\nWorld') return?
A'Hello\nWorld'
BHello World
CHello World
DError
Which statement about Python strings is true?
AStrings can only contain ASCII characters
BStrings are sequences of Unicode characters
CStrings are mutable (can be changed)
DStrings must be enclosed in single quotes only
Explain how to create strings in Python and how to include quotes inside them.
Think about how you can mix quotes or use backslashes.
You got /5 concepts.
    Describe the difference between normal strings and raw strings in Python.
    Consider how \n behaves in each.
    You got /4 concepts.