0
0
Pythonprogramming~5 mins

String length and membership test in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the len() function do when used with a string?
The len() function returns the number of characters in the string, including spaces and special characters.
Click to reveal answer
beginner
How can you check if a character or substring exists inside a string in Python?
You can use the in keyword to test membership. For example, 'a' in 'apple' returns True.
Click to reveal answer
beginner
What will len('Hello World') return?
It will return 11 because there are 11 characters including the space.
Click to reveal answer
beginner
What is the result of 'x' in 'example'?
It returns True because the character 'x' is present in the string 'example'.
Click to reveal answer
beginner
Can in be used to check for substrings longer than one character?
Yes, in works for any substring. For example, 'cat' in 'concatenate' returns True.
Click to reveal answer
What does len('Python') return?
A6
B5
C7
D0
Which expression checks if 'a' is in the string 'data'?
A'data' in 'a'
B'a' not in 'data'
C'a' in 'data'
D'data' == 'a'
What will 'z' in 'pizza' return?
AFalse
BTrue
CError
DNone
What is the length of the string '' (empty string)?
ANone
B1
CError
D0
Which of these is True?
A'cat' in 'concatenate'
B'dog' in 'concatenate'
C'bat' in 'concatenate'
D'rat' in 'concatenate'
Explain how to find the number of characters in a string and how to check if a character is inside that string.
Think about counting characters and searching inside text.
You got /4 concepts.
    Describe what happens when you use in with a substring longer than one character.
    Consider if 'cat' is in 'concatenate'.
    You got /3 concepts.