Answer the question
In order to leave comments, you need to log in
What are "data types" in Python?
The question seems to be simple, they ask at all interviews, but I don’t understand everything in the generally accepted answers to this question)
What are "data types in Python?"
Well, it is clear that this is a string, a list, a dictionary, etc.
But map, range, slice are also data types?
And everything else for which there are classes should also be included here?
That is, there are more than 40 of them? (not taking into account custom classes).
As far as I understand, all data types are classes. But is the converse true? Is each class a separate data type?
Answer the question
In order to leave comments, you need to log in
All data types are classes, but not all classes are data types. Although classes are types =) but I will not confuse you.
"map, range, slice" are not data types.
I think in that question you are referring to simple types like strings, floating point numbers, integers, and even complex ones.
Tuples (tuple) and dictionaries (dict) are already data structures, collections... whatever. Yes, technically these are also classes and in a sense they can be called types, but all this terminological jungle is useless to you.
Just think of atomic values of simple types as data types. If they get to the bottom of you with such an understanding, then you need to send such people \u003d).
Further more interesting. range, for example, is a class whose instance "can" do an arithmetic sequence generator. This word "can" is connected with the Python concept of protocols. For example, if an object can be accessed by index, then it supports the appropriate __getitem__ protocol. If the object supports slices, then a special object, the slice instance, can be passed to this method. This instance simply carries three slice parameters (beginning, end and step), and how the object will use it is at the mercy of the programmer.
You probably still need to understand the difference between mutable and immutable objects, but ... it seems to me that you decided to avoid reading textbooks and systematic study of the language, but simply decided to come here for a personal tutor who will spend his time here explaining trivial things from every first textbook?
Just trust one of the tutorials and don't try to jump over your head.
No map, range, slice are not data types. These are functions. They perform operations on data.
For classes, yes. class Int or class String describe data types and their methods (functions that can be performed on them).
If you find it difficult to understand, then imagine that the data type is the inscription on the box, which indicates what is in it.
For example, there are two boxes, one says "Toys" and the other says "Wires". These are some kind of data types.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question