0
0
Pythonprogramming~20 mins

String length and membership test in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of string length and membership test
What is the output of this Python code?
Python
s = "hello world"
result = len(s) > 5 and 'w' in s
print(result)
AFalse
BTypeError
CSyntaxError
DTrue
Attempts:
2 left
๐Ÿ’ก Hint
Check if the string length is greater than 5 and if the character 'w' is inside the string.
โ“ Predict Output
intermediate
2:00remaining
Check membership and length in a string
What will be printed by this code?
Python
text = "Python3.12"
output = ('3' in text) and (len(text) == 9)
print(output)
ANameError
BTrue
CFalse
DIndexError
Attempts:
2 left
๐Ÿ’ก Hint
Check if '3' is in the string and if the length equals 9.
โ“ Predict Output
advanced
2:00remaining
Result of combined string length and membership test
What is the output of this code snippet?
Python
s = "DataScience"
result = (len(s) < 10) or ('a' not in s)
print(result)
AFalse
BTrue
CSyntaxError
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Evaluate both conditions and then the or operation.
โ“ Predict Output
advanced
2:00remaining
Output of membership test with string length check
What does this code print?
Python
word = "challenge"
print(len(word) == 9 and 'z' in word)
AFalse
BTrue
CSyntaxError
DIndexError
Attempts:
2 left
๐Ÿ’ก Hint
Check the length and if 'z' is in the string.
๐Ÿง  Conceptual
expert
2:00remaining
Understanding string membership and length logic
Given the code below, what is the value of variable result after execution?
Python
text = "OpenAI GPT"
result = (len(text) != 10) and (' ' in text) and ('A' in text)
ATrue
BFalse
CTypeError
DNameError
Attempts:
2 left
๐Ÿ’ก Hint
Check each condition carefully and combine with 'and'.