0

What is str and int actually? (Solved)

And how does the input system work, its needed when running the program. Any help at explaining would be awesome! Tnx. Edit: Tnx Seb and David Carroll. Helped alot ;)

13th Jun 2019, 4:45 PM
Michael Butoi
3 Answers
+ 6
In Python, just as Seb TheS said, str and int are built-in classes, or more specifically, built-in types used to create new objects. For these types, they are: str: Used for string objects. int: Used for integer objects. The online documentation on this is confusing because they refer to str() and int() as built-in functions. However, these are actually class constructors used for returning object references based on the values passed in as argument. These are used to convert a value of one type into a value of another type. Ex: Convert number to string: secretToLife = str(42) Ex: Convert string to number: theNumber = int(secretToLife) Hopefully this helps and makes sense.
13th Jun 2019, 10:36 PM
David Carroll
David Carroll - avatar
+ 8
Michael, i would suggest you to continue your python course because everything you are asking for is explained there. đŸ€€ See Basic Concepts.
13th Jun 2019, 4:55 PM
Lothar
Lothar - avatar
+ 2
Actually I don't think that the Python tutorial explained the true meaning of str and int, for simplicity it told they would be just functions, in this lesson: https://www.sololearn.com/learn/Python/2284/ But really they are classes, str and int are both builtin classes, and you call their constructors __init__ or __new__, when you call the class name as a function. But ofcourse it would have been a lot more confusing for beginners, if the tutorial could have told about their real meaning instead of treating them as functions. Anyways they work like pure-functions.
13th Jun 2019, 8:06 PM
Seb TheS
Seb TheS - avatar