isinstance()issubclass()iter()len()license()20181010

def isinstance(x , A_tuple):#real signature unknown;【经常看到,依然不知道什么含义】restored from __doc__
	'''
	Return whether an object is an instance of a class of a subclass【子集】 thereof【adv. 它的;由此;在其中;关于…;将它】.

	A tuple,as in ``isinstance(x , (A,B,……))``,may be given as the target to check against.This is equivalent to ``isinstance(x , A) or isinstance(x , B) or...``etc.
	'''
	pass

	"备注:查看一个对象是不是某一个类或者其子类的对象,参数x是对象,后面的参数A_tuple可以只传一个类,也可以传包含多个类的子集 , 只要元祖内的至少一个元素isinstance()返回True,结果就是True"

函数isinstance(x , A_tuple)验证:

Python 3.7.0b4 (v3.7.0b4:eb96c37699, May  2 2018, 01:03:45) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(1,int)#1是int类的实例对象(int类型)
True
>>> isinstance(1,str)#1不是str类的实例对象(str类型)
False
>>> isinstance(1,(str,int))#1是str类或者int类的实例对象,1是int类的实例对象True,结果True
True
>>> isinstance(1 , type)
False
>>> isinstance(1 , object)#因为:(1是int类的实例对象,int类是object的子类),所以:(1算作是object的实例对象)
True
>>> 

def issubclass(x , A_tuple):#real signature unknown;restored from __doc__
	'''
	Return whether 'cls' in a derived【派生的】from another class or is the same class.

	A tuple,as in ``issubclass(x , (A,B,...))``,may be given as the target to check against.This is equivalent to ``issubclass(x , A) or issubclass(x , B) or ...``etc.
	'''
	pass
	'''备注:查看一个类是不是某一个类的子类
								或者是同一个类
			参数x是类名,后面的参数A_tuple可以只传一个类,也可以传包含多个类的子集
													传元祖时,只要x是元祖任意一个元素的子类或相同类就返回True'''

函数issubclass(x , A_tuple)验证:

>>> issubclass(int,int)
True
>>> issubclass(int,str)
False
>>> issubclass(int,object)
True
>>> issubclass(int,'something')#两个参数都必须是类或者类的元祖,’something‘是str类的实例对象
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 2 must be a class or tuple of classes
>>> issubclass(1,int)##两个参数都必须是类或者类的元祖,1是int类的实例对象
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class
>>> issubclass(int,(str,tuple,set,dict,int,float,bool))#元祖内,int和第一个参数int类一样,有一个True结果就True
True
>>> 

def iter(source , sentinel=None【哨兵,守卫】):#known special case of iter
	'''
	iter(iterable) ---> iterator【迭代器】
	iter(callable , sentinel) ---> iterator

	Get an iterator from an object. In the first form,the argument must supply its own iterator,or be a sequence【 序列】.
	In the second form,the callable is called until it returns the sentinel.
	'''
	pass
	'''
	备注:iter()用来生成迭代器,有两种形式,
				第一种是直接把可迭代对象变成迭代器,
						从for循环的角度来讲,iter()没卵用,比如list类型是可迭代的,可以直接for循环
								iter(list)后也是可以for 循环
								  迭代器是可迭代的,但是可迭代的不一定是迭代器,(可迭代的对象还有其他的,比如list,tuple还有字典)
				第二种比较陌生,有两个参数,第一个为可调用的(就是可以加括号执行的,比如函数),第一个参数字面意思是哨兵,个人理解为是只要把这个sentinel迭代出来这个迭代器就停止

	'''


iter()详见菜鸟教程:https://www.cnblogs.com/yitouniu/p/5243136.html

def len(*args , **kwargs):#real signature unknown
	'''
	Return the number of items in a container【】.
	'''
	pass
	'''看一个项目的长度,不是占的字节数,而是元素个数'''

>>> s = '123456789'
>>> i = 123456789
>>> l = [1,2,3,4,5]
>>> d = {1:1,2:2,3:3,4:4,5:5}
>>> len(s)
9
>>> len(i)#整数和浮点都不能查看len
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'int' has no len()
>>> len(l)
5
>>> len(d)
5
>>> 
>>> s_chinese = '我是中国人,我爱祖国'#加上逗号算十个字,但是大小是30bytes了
>>> len(s_chinese)
10
>>> len(s_chinese.encode())
30
>>> import json
>>> len(json.dumps({1:1,2:2,3:3,4:4,5:5}))#5个元素,占40bytes
40
>>> 

def license(*args , **kwargs):#real signature unknown
	'''
	interactive prompt objects for printing the license text,a list of contrbutors and the copyright notice.
	'''
	pass
	'''备注:和copyright() ,credits()差不多,看版权,作者,贡献者,认证什么的'''

Python 3.7.0b4 (v3.7.0b4:eb96c37699, May  2 2018, 01:03:45) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> license()
A. HISTORY OF THE SOFTWARE
==========================

Python was created in the early 1990s by Guido van Rossum at Stichting
Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands
as a successor of a language called ABC.  Guido remains Python's
principal author, although it includes many contributions from others.

In 1995, Guido continued his work on Python at the Corporation for
National Research Initiatives (CNRI, see http://www.cnri.reston.va.us)
in Reston, Virginia where he released several versions of the
software.

In May 2000, Guido and the Python core development team moved to
BeOpen.com to form the BeOpen PythonLabs team.  In October of the same
year, the PythonLabs team moved to Digital Creations, which became
Zope Corporation.  In 2001, the Python Software Foundation (PSF, see
https://www.python.org/psf/) was formed, a non-profit organization
created specifically to own Python-related Intellectual Property.
Zope Corporation was a sponsoring member of the PSF.

All Python releases are Open Source (see http://www.opensource.org for
the Open Source Definition).  Historically, most, but not all, Python
Hit Return for more, or q (and Return) to quit: 


posted @ 2018-10-10 10:43  Charles_Wu  阅读(136)  评论(0编辑  收藏  举报