PYTHON3 内置函数 技术教程文章

Python内置函数id

英文文档:id(object)Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the sameid() value.CPython implementation detail: This is the address of the object in memory.说明:  1. 返回对象的唯一标识符,用整数表示。在程序生命周期内,这个标识符常量是唯一的。>>> a...

Python内置函数

英文文档:hex(x)Convert an integer number to a lowercase hexadecimal string prefixed with “0x”, for exampleIf x is not a Python int object, it has to define an __index__() method that returns an integer. 说明:  1. 函数功能将10进制整数转换成16进制整数。>>> hex(15)0xf>>> hex(16)0x10 2. 如果参数x不是整数,则它必须定义一个返回整数的__index__函数。# 未定义__index__函数 >>> class Student:def __ini...

Python内置函数locals

英文文档:locals()Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks. 说明:  1. 函数功能返回当前作用域内的局部变量和其值组成的字典,与globals函数类似(返回全局变量)>>> locals() {__package__: None, __loader__: <class _frozen_importlib.BuiltinImporter>, __doc__: None, __na...

Python内置函数help

英文文档:help([object])Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any...

Python内置函数len

英文文档:len(s)Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).说明: 1. 返回对象的长度,参数可以是序列(比如字符串、字节数组、元组、列表和range对象),或者是集合(比如字典、集合、不可变集合)>>> len(abcd) # 字符串 >>> len(bytes(abcd,utf-8)) # 字节数组 >>> ...

Python内置函数bin()oct()等实现进制转换

使用Python内置函数:bin()、oct()、int()、hex()可实现进制转换。 先看Python官方文档中对这几个内置函数的描述: bin(x) Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. oct(x) Convert an integer number to an octal string. The result is a valid Python expression. If x is...

Python入门及进阶笔记Python内置函数小结

内置函数 常用函数 1.数学相关 ?abs(x) abs()返回一个数字的绝对值。如果给出复数,返回值就是该复数的模。代码如下: >>>print abs(-100) 100 >>>print abs(1+2j) 2.2360679775?divmod(x,y) divmod(x,y)函数完成除法运算,返回商和余数。代码如下: >>> divmod(10,3) (3, 1) >>> divmod(9,3) (3, 0)?pow(x,y[,z]) pow()函数返回以x为底,y为指数的幂。如果给出z值,该函数就计算x的y次幂值被z取模的值。代码如下: >>> print po...

Python内置函数的用法实例教程

本文简单的分析了Python中常用的内置函数的用法,分享给大家供大家参考之用。具体分析如下: 一般来说,在Python中内置了很多有用的函数,我们可以直接调用。 而要调用一个函数,就需要知道函数的名称和参数,比如求绝对值的函数abs,只有一个参数。可以直接从Python的官方网站查看文档:http://docs.python.org/2/library/functions.html#abs 也可以在交互式命令行通过help(abs)查看abs函数的帮助信息。 调用abs函数:>>> abs(100...

Python内置函数之filtermapreduce介绍

Python内置了一些非常有趣、有用的函数,如:filter、map、reduce,都是对一个集合进行处理,filter很容易理解用于过滤,map用于映射,reduce用于归并. 是Python列表方法的三架马车。1. filter函数的功能相当于过滤器。调用一个布尔函数bool_func来迭代遍历每个seq中的元素;返回一个使bool_seq返回值为true的元素的序列。>>> N=range(10) >>> print filter(lambda x:x>5,N) [6, 7, 8, 9] 2. map函数func作用于给定序列的每个元素,...

Python内置函数dir详解

1.命令介绍 最近学习并使用了一个python的内置函数dir,首先help一下:代码如下: >>> help(dir) Help on built-in function dir in module __builtin__:dir()dir([object]) -> list of strings Return an alphabetized list of names comprising (some of) the attributesof the given object, and of attributes reachable from it: No argument: the names in the current scope.Module object: the module attributes.Type or...

python中__call__内置函数用法实例

本文实例讲述了python中__call__内置函数的用法。分享给大家供大家参考。具体分析如下: 对象通过提供__call__(slef, [,*args [,**kwargs]])方法可以模拟函数的行为,如果一个对象x提供了该方法,就可以像函数一样使用它,也就是说x(arg1, arg2...) 等同于调用x.__call__(self, arg1, arg2)。模拟函数的对象可以用于创建仿函数(functor) 或代理(proxy)class DistanceForm(object):def __init__(self, origin):self.origin = origin...

Python常用内置函数总结

一、数学相关 1、绝对值:abs(-1) 2、最大最小值:max([1,2,3])、min([1,2,3]) 3、序列长度:len(abc)、len([1,2,3])、len((1,2,3)) 4、取模:divmod(5,2)//(2,1) 5、乘方:pow(2,3,4)//2**3/4 6、浮点数:round(1)//1.0 二、功能相关 1、函数是否可调用:callable(funcname),注意,funcname变量要定义过 2、类型判断:isinstance(x,list/int) 3、比较:cmp(hello,hello) 4、快速生成序列:(x)range([start,] stop[, step]) 三、类...

Python内置函数Type()函数一个有趣的用法

今天在网上看到type的一段代码 ,然后查了一下文档,才知道type还有三个参数的用法。 http://docs.python.org/2/library/functions.html#type 以前只是知道type可以检测对象类型。然后发现了一个有趣的用法。代码如下: def println(self): a = 1 + 1 print “%s,%s” % (self.aa, a) A = type(‘A,(),{‘aa:print a, ‘println: println}) a = A() type(a) Out[11]: __main__.A a.println() print a,2第一个参数是类的名字,第二个...

Python标准库内置函数complex介绍

本函数可以使用参数real + imag*j方式创建一个复数。也可以转换一个字符串的数字为复数;或者转换一个数字为复数。如果第一个参数是字符串,第二个参数不用填写,会解释这个字符串且返回复数;不过,第二个参数不能输入字符串方式,否则会出错。real和imag参数可以输入数字,如果imag参数没有输入,默认它就是零值,这个函数就相当于int()或float()的功能。如果real和imag参数都输入零,这个函数就返回0j。有了这个函数,就可以很方...

[oldboy-django][5python基础][内置函数]zip

coding= utf-8# zip 多个可迭代对象同时跑,然后各自的值组合起来# 长度不对等情况 L1 = [1, 2, 3] L2 = ‘abcd‘ z = zip(L1, L2) print(list(z)) # 输出[(1, ‘a‘), (2, ‘b‘), (3, ‘c‘)]# 长度对等 L1 = [1, 2, 3] L2 = ‘ccd‘ z = zip(L1, L2) print(list(z))# 输出[(1, ‘c‘), (2, ‘c‘), (3, ‘d‘)]# 变量zip生成器 name = [‘Celia‘, ‘Lisa‘, ‘Marie‘] len_name = [len(n) for n in name] for name, len_name ...

Python(九):递归+内置函数+第三方模块+md5加密+操作mysql【代码】【图】

帮你循环调用函数,如果函数返回false,那么就过滤掉这个值,是指从你传入这个list里面过滤4、max()求最大值5、sum()求和6、round:保留几位小数7、chr:把数字转成对应的ascii码表里对应的值8、ord:把字母转成对应的ascii码表里对应的数字9、dir:查看某个对象里有哪些方法10、bool:布尔类型的,返回TRUE false11、eval()执行一些简单的Python代码,运算、定义变量12、exec#执行一些复杂的代码,exec函数没有返回值就是none 13、zi...

python的数据类型和部分内置函数【代码】【图】

python的数据类型 整型 int int 既是整型的代表,又是定义整型的内置函数 python2中有long类型,在python3中已被弃用 count = int(100) count = 100浮点型 float float 既是浮点型的代表,又是定义浮点型的内置函数 定义float类型的时候,并不需要一定使用float来声明 p = float(3.14) p = 3.14字符串 str 用’’ 或"" 包裹的信息,就是字符串,字符串中可以包含任意字符:字母,数字,符号。且没有顺序 字符串不可改变 safe = str...

python内置函数介绍【图】

前言内置函数,一般都是因为使用频率比较频繁,所以通过内置函数的形式提供出来。对内置函数通过分类分析,基本的数据操作有数学运算、逻辑操作、集合操作、字符串操作等。说起我正式了解内置函数之前,接触到的是lambda,通过学习发现lambda竟然是一个表达式,而我们需要要知道的是它能做什么?什么时候能用它?怎么用?首先我们可以举一个例子。a=lambda x:x+2print a(1)其实上面的程序类似于以下函数:def f(x):return x+2print...

12个python中数据处理常用的内置函数【代码】

前言 本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。 PS:如有需要Python学习资料的小伙伴可以点击下方链接自行获取 Python免费学习资料、代码以及交流解答点击即可加入在python数据分析中,经常需要对字符串进行各种处理,例如拼接字符串、检索字符串等。下面我将对python中常用的内置字符串操作函数进行介绍。 1.计算字符串的长度-len()函数 ''' 如有需要Python学习资料...

python基础(7)内置函数divmod用法【代码】

前言 我们都知道,python中//代表整数运算中的取整,%代表整数运算中的取余,那么有什么函数可以同时取到整数和余数吗? 答案是有的,使用python内置函数divmod divmod 首先看一下源码解析 def divmod(x, y): # known case of builtins.divmod""" Return the tuple (x//y, x%y). Invariant: div*y + mod == x. """return (0, 0)实际上,返回的是一个元组,元组中有2个元素,x//y就代表取整,x%y就代表取余 例子 print(divmod(...