【python内置函数】教程文章相关的互联网学习教程文章

Python内置函数——repr&str

Python内置函数——repr & strrepr & strrepr(object) & str(object)变量值被转换为字符串的两种机制:前者的目标是准确性,后者的目标是可读性repr(object)返回一个表示对象的可打印的字符串。这和通过转换(反引号``)处理得到的结果一致。作为一个普通函数,可以使用这个运算有些时候是有用处的。对于大部分类型,这个函数尝试返回一个字符串,当其传给eval(),将生成同样的对象,(即eval(repr(object)==object.)否则生成一个用...

Python快速教程(补充篇03):Python内置函数清单

Python内置(built-in)函数随着python解释器的运行而创建。在Python的程序中,你可以随时调用这些函数,不需要定义。最常见的内置函数是:PRint(“Hello World!”)在Python教程中,我们已经提到下面一些内置函数:基本数据类型 type()反过头来看看 dir() help() len()词典 len()文本文件的输入输出 open()循环设计 range() enumerate() zip()循环对象 iter()函数对象 map() filter() reduce() 下面我采取的都是实际的参数,你可以直接...

Python内置函数OCT详解

英文文档:oct ( x ) Convert an integer number to an octal string. The result is a valid Python expression. If x is not a Pythonobject, it has to define anmethod that returns an integer.说明:1. 函数功能将一个整数转换成8进制字符串。如果传入浮点数或者字符串均会报错。>>> a = oct(10)>>> a 0o12 >>> type(a) # 返回结果类型是字符串 <class str>>>> oct(10.0) # 浮点数不能转换成8进制 Traceback (most recent c...

Pythonmax内置函数详细介绍

Python max内置函数 max(iterable, *[, key, default]) max(arg1, arg2, *args[, key]) Return the largest item in an iterable or the largest of two or more arguments. If one positional argument is provided, it should be an iterable. The largest item in the iterable is returned. If two or more positional arguments are provided, the largest of the positional arguments is returned. There are two optional ...

Python内置函数complex详解

英文文档: class complex([real[, imag]]) Return a complex number with the value real + imag*1j or convert a string or number to a complex number. If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is o...

Python内置函数清单

1、数学运算 abs(-5) # 取绝对值,也就是5 round(2.6) # 四舍五入取整,也就是3.0 pow(2, 3) # 相当于2**3,如果是pow(2, 3, 5),相当于2**3 % 5 cmp(2.3, 3.2) # 比较两个数的大小 divmod(9,2) # 返回除法结果和余数 max([1,5,2,9]) # 求最大值 min([9,2,-4,2]) # 求最小值 ...

Python内置函数input

英文文档:input([prompt])If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised 说明:  1. 如果提供了promat参数,首先将参数值输出到标准的输出,并且不换行。函数读取用户输入的值,将其转换成字符串。>>> s = ...

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内置函数之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作用于给定序列的每个元素,...