I'm just starting to learn Python. I find the type system a little difficult to understand. I have a number of questions, but first of all a short reduction of a short story; The documentation states:
"All data in a Python program is represented by objects ... Each object has an identifier, type, and value."
No problems. But in addition, it is not actually described what "objects" are. For example, documents do not even cover the fact that these "objects" support the point operator - from my PoV they can be part of a memory data structure that is not exposed to the user outside id(), type()etc. However, I understand that there is some basic metaobject interface similar to that described for an instance type object in documents. To work with an example:
id()
type()
If I do this on an instance of class "x":
x.__class__.__name__
I get the name of my class. I understand it. The documentation describes the properties of __class__both __name__class instances and class type objects. If I do this [].__class__.__name__, I will get a "list". Similarly int(1).__class__.__name__it gives "int". Its ambiguity for me is exactly what is happening under the hood, and I would like to clarify. So my questions are:
__class__
__name__
[].__class__.__name__
int(1).__class__.__name__
1,2, 4- 3-:
, , API. "", "", - ""... .
Python, , OOPL. Python , OOPL, . object Python. , object "" object - .
object
, Python (2,2 ) "" "" ( ). , "int", - (, , ). , x = int(1) int () int, x.
x = int(1)
int
, Python ; , , "-" - , . , ; , . : Python - , . , "". type . , , __bases__ . , , object. . http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html.
, . > , . , ( ), . .
Python - , ( - ). , , , .
- , , .
Python 3 . "" ( ), "" (, , , ) .
( , -, , Python, . , , ).
() - , , .
__class__ ( type() ). , , , , . .
, .
- . Python, , , .. , type. , , , , .
type
>>> type(int) <type 'type'> >>> type(1) <type 'int'> >>> class Foo(object): ... pass >>> type(Foo) <type 'type'> >>> obj = Foo() >>> type(obj) <class '__main__.Foo'>
( type(x) x.__class__.)
type(x)
x.__class__
Source: https://habr.com/ru/post/1537367/More articles:Parallel sorting in java8 returns invalid result - javaКак сделать отступ текстовой строки в TextView в Android? - androidUnity code coding errors - c #How to stop lex from replacing characters as a sign? - haskellrepeat the result several times in MySQL - sqlDisplay non ascii (japanese) characters in pandas story legend - pythonIs it possible to have TypeScript support in Visual Studio Express for Windows? - windows-store-appsMac Zlib ndefined characters for x86_64 architecture: - c ++How to enable / disable double buffer in mysql? - mysqlChange output without changing code - javaAll Articles