Remember
isalpha() requires a nonempty string made entirely of Unicode letters; it is not limited to ASCII.
isalpha() requires a nonempty string made entirely of Unicode letters; it is not limited to ASCII.
Follow the example, change its sample, and compare what happens.
Explain the result and test your understanding.
Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.
Follow the code and watch its state change. Guided simulation.
text = 'café'
result = text.isalpha()
print(result)Top-level scope
'café'Object 2 · boolTrueisalpha() requires a nonempty string made entirely of Unicode letters; it is not limited to ASCII.
(no output)
What do you expect this program to print?
EXAMPLE INSTRUCTIONS
text = 'café'
result = text.isalpha()
print(result)
|
v
DISPLAYED RESULT
True
FINAL BINDINGS
text --> object 1 (str)
result --> object 2 (bool)
object 1: 'café'
object 2: TrueChoose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.
Choose a sample and follow its execution. Guided simulation.
text = 'café'
result = text.isalpha()
print(result)Top-level scope
'café'Object 2 · boolTrueThe example has finished. Compare the final output with the values and references above.
True
What do you expect this program to print?
text = 'café'
result = text.isalpha()
print(result)isalpha() MethodThe isalpha() method in Python checks if all characters in a string are alphabetic (letters A-Z and a-z). It's useful for input validation, data filtering, and more.
string.isalpha()
True – If all characters are alphabetic and the string is not empty.False – If there are any non-alphabetic characters (numbers, spaces, symbols, etc.) or if the string is empty.text = "Python"
print(text.isalpha())
True
text = "Python3"
print(text.isalpha())
False
text = "Hello World"
print(text.isalpha())
False
text = ""
print(text.isalpha())
False
isalpha() returns True for letters in other languages too. For example:
print("नमस्ते".isalpha())
True
isalnum() instead).isalpha() is commonly used in input sanitization and parsing problems in coding interviews and online judges.
isalpha() checks if all characters in the string are letters.False if there are spaces, digits, or symbols.False on an empty string.Ask the user to enter a name and print whether it is valid (contains only letters):
name = input("Enter your name: ")
if name.isalpha():
print("Valid name!")
else:
print("Invalid name. Please use only letters.")
Connect what you noticed in the example with the idea below.
isalpha() requires a nonempty string made entirely of Unicode letters; it is not limited to ASCII.
isalpha() recognizes only A–Z and a–z.
This is the misconception to avoid.Reference checks are optional and do not count toward course progress.