1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How can I check if string input is a number?

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    How do I check if a user's string input is a number (e.g., -1, 0, 1, etc.)?

    user_input = input("Enter something:")

    if type(user_input) == int:
    print("Is a number")
    else:
    print("Not a number")


    The above won't work since input always returns a string.

    Continue reading...

Compartilhe esta Página