How To Check If The User Input Is A String In Python 3
I wrote the code below:  try:     nums=input('Write a name:')     print (nums) except ValueError:     print ('You didn't type a name')  The problem is that even the user enter a nu
Solution 1:
You can use the function yourstring.isalpha() it will return true if all characters in the string are from the alphabet.
So for your example:
nums = input("write a name:")
if(not nums.isalpha()):
    print("you did not write a name!")
    returnprint(nums)
Solution 2:
You can use the builtin Python function type() to determine the type of a variable.
Post a Comment for "How To Check If The User Input Is A String In Python 3"