Showing posts with label types. Show all posts
Showing posts with label types. Show all posts

Wednesday, February 8, 2012

type() and input()

Playing around with type(), a handy function that shows the type of data stored, and input():

using python's type() to see what sort of data is in a variable. input()'s behavior is different to that of the interpreter, data is always a string where the interpreter can figure out the data type.


The interpreter teaches the concept that data types will be recognised at input. When using the input() function, however, all data is treated as a string. This is documented, but it's not apparently consistent to new users.

The fix is simple, but this also assumes the input data can be converted.

I'm new to this, there may be some other function that accepts and validates only numeric input data.