1.isinstance function: In addition to taking a type as a parameter, it can also take a type tuple as a parameter.
isinstance(obj,basestring)===isinstance(obj,(str,unicode))
2.getattr function: You can give a default value to avoid triggering errors.
writte=getattr(obj,'write',sys.stdout.write)
3.type function: You can get the type of an object or create a new type directly from it:
>>> Point=type('Point',(object,),{'x':0,'y':0}) >>> p=Point() >>> p.x,p.y (0, 0) >>> p=Point(3,8) Traceback (most recent call last): File "<pyshell#55>", line 1, in <module> p=Point(3,8) TypeError: object() takes no parameters >>> pprint.pprint(dir(Point)) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'x', 'y'] >>> p.name='source point' >>> p.name 'source point' >>> pprint.pprint(dir(p)) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name', 'x', 'y'] >>> def tostr(self): return '(%s,%s)'%(self.x,self.y) >>> Point.__str__=tostr >>> print p (0,0) >>> def init(self,x,y): self.x,self.y=x,y >>> Point.__init__=init >>> p2=Point(6,8) >>> print p2 (6,8) >>>
4.issubclass(bool,int)==True
5.numbers. Number is the base class of all numerical types
6.type(None)==NoneType, None is a constant
7.In addition to the iter(object) form, the iter function also returns an iterator object (callable, sentinel)
>>> def getrand(): import random return random.randint(1,100) >>> for i in iter(getrand,50):print i,#获取第一次得到50之前的所有1-100的随机数 32 19 82 28 30 41 100 39 71 29 45 30 94 77 62 26 25 19 82 20 55 20 43 73 >>> for i in iter(getrand,50):print i,#获取第一次得到50之前的所有1-100的随机数 22 54 14 25 60 65 16 80 61 5 48 61 2 30 90 98 70 10 55 45 23 72 87 39 70 3 84 85 >>>
8.BaseException is the base class of all exceptions, Exception is just the base class of all exceptions that do not exit
9.locals/globals/vars/dir:
[1]locals/globals is very simple, Is a local/global object dict relative to the current scope;
[2]vars()==locals(), vars(obj)==obj.__dict__
[3] has no parameters, set(dir()) ==set(locals().keys()); if hasattr(obj,'__dir__')=>dir(obj)==obj.__dir__(); Otherwise, if obj is a module object, dir(obj) returns are all attributes of the module; if obj is a class object, dir(obj) returns all the attributes of the class, and then the attributes inherited from the base class; if obj is an instance object, dir(obj) returns the instance object Some attributes, attributes of the class to which it belongs, and attributes inherited from the base class of the class to which it belongs. [Any modification to a class object will be reflected on its instance object; any modification to the base class will also be reflected on the derived class. Of course, except for the case of attribute masking. 】
10.enumerate function: enumerate(obj,[start]), if start is defined, the ordinal will start from start, not from the default zero.
>>> for i,name in enumerate(['C','C++','CSharp','Java','Python'],1): print '%d.%s'%(i,name) 1.C 2.C++ 3.CSharp 4.Java 5.Python >>>

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor
