2021-10-04-Learning notes P-4, Python

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

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
 

目录

1. Row connector

2. Object in python

-id()

-type()

-Example

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. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值