This article is the author's original, reproduced also please indicate the source.
This article only represents the author's own views, for reference only. If you have any objection, you are welcome to discuss.
Forrest
目录
Defination of object in python
1. Row connector
Row connector intend to connect two rows as one row in syntax.
Python 3.9.7 (v3.9.7:1016ef3790, Aug 30 2021, 16:25:35)
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> print("row-connector")
row-connector
>>> string = "abcdefghijklmnopqrstuvwxyz"
>>> string
'abcdefghijklmnopqrstuvwxyz'
>>> string_ = "abcdefgh\"
SyntaxError: EOL while scanning string literal
>>> string2 = "abcdefgh\
ijklmnopqrstuvwxy\
z"
>>> string2
'abcdefghijklmnopqrstuvwxyz'
>>> array = [1, 34, 545, 67, 009, 4, 655303]
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> array = [1, 34, 545, 67, 9, 4, 655303]
>>> array
[1, 34, 545, 67, 9, 4, 655303]
>>> array = [1, 3, 4\
, 3, 4, 5, 3, 90]
>>> array
[1, 3, 4, 3, 4, 5, 3, 90]
>>>
2. Object in python
As we all known, python is an objective programming language.
Let us see two functions:
-id()
This funciton intends to show the address code of an object.
-type()
This one intends to show the type of the object. 
Futhermore, we could get more usages from the hint when you are coding.
-Example
>>> string = "abcdefghijklmnopqrstuvwxyz"
>>> string
'abcdefghijklmnopqrstuvwxyz'
>>> string2 = "abcdefgh\
ijklmnopqrstuvwxy\
z"
>>> string2
'abcdefghijklmnopqrstuvwxyz'
>>> array = [1, 34, 545, 67, 9, 4, 655303]
>>> array
[1, 34, 545, 67, 9, 4, 655303]
>>> array = [1, 3, 4\
, 3, 4, 5, 3, 90]
>>> array
[1, 3, 4, 3, 4, 5, 3, 90]
>>>
>>> id(array)
4360215104
>>> type(array)
<class 'list'>
>>> id(string)
4350198288 # we can see here, the same string is from the same address!
>>> id(string2)
4350198288 # we can see here, the same string is from the same address!
>>> type(string)
<class 'str'>
>>>
There is a funny findings, when you named, defined two variables with same value for example in the instance above the 'string' and 'string2' is the same content, and the address is same.
Defination of object in python
a block of memory, has its particular type and value, available for some relevant operations

The reference

Above example is from GaoQi sxt lesson video.
本文探讨Python编程中关于对象的概念,包括行连接器和Python对象的特性。介绍了-id()和-type()函数,用于显示对象的地址码和类型。举例说明即使变量值相同,其内存地址也可能相同,进一步阐述了Python对象定义为具有特定类型和值的内存块。

1625

被折叠的 条评论
为什么被折叠?



