Complete the code to check if the string contains only digits.
text = "12345" result = text.[1]() print(result)
The isdigit() method returns True if all characters in the string are digits.
Complete the code to check if the string contains only alphabetic characters.
word = "Hello" if word.[1](): print("All letters") else: print("Contains other characters")
The isalpha() method returns True if all characters in the string are letters.
Fix the error in the code to check if the string contains only whitespace characters.
space_str = " \t\n" print(space_str.[1]())
The isspace() method returns True if all characters in the string are whitespace characters like spaces, tabs, or newlines.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.
words = ["apple", "cat", "banana", "dog"] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words with length greater than 4.
words = ["tree", "flower", "grass", "bush"] result = { [1]: [2] for w in words if len(w) [3] 4 } print(result)
The dictionary comprehension uses w.upper() as keys, len(w) as values, and filters words with length greater than 4 using >.