I am currently writing some python code that asks for a users name. I need the program to validate whether the user's input is a string or not. If it is a string, The loop will break and the programme will continue. If the input is not a string (like a float, integer etc), It will loop around and ask the user to input a valid string. I understand that you can use the following code when you are checking for an integer;
while True:
try:
number = int(input("Plese enter a number: "))
break
except ValueError:
print("Please enter a valid integer")
I was thinking that I could use something like this to check for a string;
while True:
try:
word = str(input("Plese enter a string: "))
break
except ValueError:
print("Please enter a valid string")
But as far as I understand, the str() just converts the user's input to a string, regardless of the data that was entered.
Please help!
thanks