0
im confused
one of my lessons on python was talking about a new command called "type" means. for axaple (i took it out of a lesson) balance = "780" type(balance) what does that mean? also i dont understand what "input" means coding wise
4 Answers
+ 3
Hi print ("JUMP_LINK__&&__python__&&__JUMP_LINK"),
(1) type: It shows the kind of data, like âstrâ for text or âintâ for numbers.
(2) input: It asks the user to type something and saves it in your code.
+ 2
print ("JUMP_LINK__&&__python__&&__JUMP_LINK") there's code behind the type() function, which someone else wrote so that future users could use it easily, like input() or print().
The code behind it must run some kind of test to evaluate the variable it is told to check.
+ 1
Thanks for the iput
But how does type know what the type of thing is...im confused
0
print ("JUMP_LINK__&&__python__&&__JUMP_LINK") ,
here is a short description (simplified) that may help you:
when we create a variable in python by assigning a value to it, not only this value is stored in the object (instance of a class), but also some metadata like the object type. one field of this metadata is `__class__`.
type() can read the content of this field.
> how python can detect the type of the data that we assign:
when creating an object, python can detect a values type in different ways. it can be done by using :
> literals in the code like 42 or 3.24 or 'hello'.
> elements like brackets () or [] or {}
> constructors like: int('42')
>...