priya_input = "Hello123"
if priya_input.isalpha():
print("Only letters")
elif priya_input.isalnum():
print("Letters and numbers")
else:
print("Other characters")Identify what Priya's code outputs when using the isalpha() method to validate string content
Only letters
Letters and numbers
Other characters
Error: isalpha() and isalnum() cannot be used together
Show answer & explanationAnswer
Correct answer
Letters and numbers
Explanation
isalpha() returns False because the string contains digits, but isalnum() returns True because it contains both letters and numbers, so it prints 'Letters and numbers'.
Written by ExamHoot EditorialPublished · Updated
All 40 String Methods and Manipulation questions
- 1.What does the upper() method do to a string in Python?
- 2.What will be the output when you call the lower() method on the string 'HELLO World'?
- 3.What does the len() function return when applied to a string?
- 4.What is the purpose of the strip() method in Python string manipulation?
- 5.How does the replace() method work when called on a string?
- 6.What does the split() method do when called without any arguments?
- 7.What does the find() method return when the substring is found in a string?
- 8.What is the purpose of the capitalize() method in string manipulation?
- 9.What does the join() method do when called on a string?
- 10.What does the count() method return when called on a string?
- 11.What is the difference between the startswith() and endswith() methods?
- 12.What does the isdigit() method return when called on a string containing only numbers?
- 13.What does the isalpha() method check in a Python string?
- 14.What does the title() method do to a string in Python?
- 15.What does the swapcase() method return when applied to a string?
- 16.What is the purpose of the strip() method when applied to a string in Python?
- 17.Predict the output of the following code that uses string methods to manipulate text
- 18.What is the difference between the find() and index() methods when searching for a substring?
- 19.Predict what value Hari's string variable will contain after executing this code snippet
- 20.What will be the output when Prasath runs this code that uses the count() method on a string?
- 21.Explain what the startswith() method does and when it would be useful in practical programming
- 22.What is the output of this code where Vikram uses the upper() and slice operations together?
- 23.Predict the output when Deepak uses the isdigit() method to check string content
- 24.What does the swapcase() method accomplish when applied to a string in Python?
- 25.Predict what Anjali's code will output when using the rfind() method to search from the right
- 26.What will be the output when Rohan executes this complex string manipulation code using multiple chained methods?
- 27.Identify the bug in Meera's code that attempts to validate an email address format
- 28.What is the output of this code where Arun uses string slicing combined with the find() method?
- 29.Predict the output when Sneha uses the split() method with a maximum split parameter
- 30.What will be the output of this code where Karthik uses the join() method with a list comprehension?
- 31.Identify what Priya's code outputs when using the isalpha() method to validate string content
- 32.What is the output when Arjun uses the zfill() method to pad a string with leading zeros?
- 33.Predict the output of this code where Neha uses the partition() method to split a string
- 34.What will Sanjay's code output when using the expandtabs() method with custom tab width?
- 35.Analyze what Divya's code will output when using the translate() method with a translation table
- 36.What will be the output of the following code when Hari tries to count occurrences of a substring in a string?
- 37.Predict the output when Prasath executes this code to find the index of a character in a string using the find() method
- 38.What is the difference between the replace() and replaceall() methods when manipulating strings in Python?
- 39.Predict what will be displayed when Arjun runs this code involving string slicing and the upper() method
- 40.What will be the output when Deepak uses the split() method to break down a comma-separated string into individual elements?
