Which Python statement correctly verifies that a user's input does not contain any spaces?
easy📝 Syntax Q3 of Q15
Testing Fundamentals - Non-Functional Testing
Which Python statement correctly verifies that a user's input does not contain any spaces?
Aif ' ' not in user_input:
Bif user_input.contains(' '):
Cif user_input.indexOf(' ') == -1:
Dif user_input.has(' '):
Step-by-Step Solution
Solution:
Step 1: Understand Python syntax for substring check
In Python, the correct way to check if a substring is not present is using the 'not in' keyword.
Step 2: Analyze each option
if ' ' not in user_input: uses 'if ' ' not in user_input:', which is valid Python syntax. if user_input.contains(' '): uses 'contains', which is not a Python string method. if user_input.indexOf(' ') == -1: uses 'indexOf', which is JavaScript syntax. if user_input.has(' '): uses 'has', which is not a Python string method.
Final Answer:
if ' ' not in user_input: -> Option A
Quick Check:
Check Python substring syntax [OK]
Quick Trick:Use 'in' or 'not in' for substring checks in Python [OK]
Common Mistakes:
MISTAKES
Using JavaScript methods like contains or indexOf in Python
Confusing syntax for substring presence check
Master "Non-Functional Testing" in Testing Fundamentals
9 interactive learning modes - each teaches the same concept differently