Python开发 標準內建方法 (未完代補)
abs(number) 絕對值
The abs() method takes a single argument:
num - number whose absolute value is to be returned. The number can be:
- integer
- floating number
- complex number
any(iterable)
The any() method returns True if any element of an iterable is True. If not, any() returns False.
*iterable(list, string, dictionary, tumple ...)
Trueif at least one element of an iterable is trueFalseif all elements are false or if an iterable is empty (表 "0", "False", empty
all(iterable)
The all() method returns True when all elements in the given iterable are true. If not, it returns False.
ascii(object) ascii編碼(拉丁字母)
The ascii() method returns a string containing a printable representation of an object. It escapes the non-ASCII characters in the string using \x, \u or \U escapes.
*object (like: strings, list etc).
bin(num) 轉二進制
The bin() method converts and returns the binary equivalent string of a given integer. If the parameter isn't an integer, it has to implement __index__() method to return an integer.
- num - an integer number whose binary equivalent is to be calculated.
- If not an integer, should implement
__index__()method to return an integer
number = 5
print('The binary equivalent of 5 is:', bin(number))
The binary equivalent of 5 is: 0b101
bool([value]) 轉布爾值
The bool() method converts a value to Boolean (True or False) using the standard truth testing procedure.
The following values are considered false in Python:
NoneFalse- Zero of any numeric type. For example,
0,0.0,0j - Empty sequence. For example,
(),[],''. - Empty mapping. For example,
{} - objects of Classes which has
__bool__()or__len()__method which returns0orFalse
bytearray([source[, encoding[, errors]]])
The bytearray() method returns a bytearray object which is a mutable (can be modified) sequence of integers in the range 0 <=x < 256.
If you want the immutable version, use bytes([source[, encoding[, errors]]]) method.
callable(object) object是否定義過
The callable() method returns True if the object passed appears callable. If not, it returns False.
chr(i) 回傳unicode的對應值
The chrt() method returns a character (a string) from an integer (represents unicode code point of the character).
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
The compile() method returns a Python code object from the source (normal string, a byte string, or an AST object).
The code object returned by the compile() method can later be called using methods like: exec() and eval() which will execute dynamically generated Python code.

exec(object, globals, locals)
The exec() method executes the dynamically created program, which is either a string or a code object.
eval(expression, globals=None, locals=None)
The eval() method parses the expression passed to this method and runs python expression (code) within the program.

classmethod(function)
The classmethod() method returns a class method for the given function.
- function - Function that needs to be converted into a class method
@classmethod 高端裝飾,接在 def Person.printAge()之前,效果同等 Person.printAge = classmethod(Person.printAge)
未完待續
https://www.programiz.com/python-programming/methods/built-in/classmethod
Python开发 標準內建方法 (未完代補)的更多相关文章
- Python开发 基礎知識 (未完代補)
一.Python基本知識 1.Python屬高階語言,所編築的是字節碼 2.一般狀態statement 終止於換行,如需使用多數行編寫,可在行末加上 \,以表延續 但在 parentheses ( ) ...
- 查看Python的版本、内建方法和模块等内容的方法
若想更好地应用Python帮助我们解决日常生活的问题,就必须了解清楚它的内建方法和模块等特性.相信不少同学在安装某个版本的Python后,对于内建方法之类都是一知半解,希望本文能帮助了解Python的 ...
- windows下Python开发错误记录以及解决方法
windows下使用pip提示ImportError: cannot import name 'main' 原因:将pip更新为10.0.0后库里面的函数有所变动造成这个问题 解决方法:先卸载现在的p ...
- python快速学习-常用內建模块
- python开发必备pycharm专业版破解方法
修改hosts文件 添加下面一行到hosts文件,目的是屏蔽掉Pycharm对激活码的验证 0.0.0.0 account.jetbrains.com 注:hosts文件路径,Windows在C:\W ...
- python开发_configparser_解析.ini配置文件工具_完整版_博主推荐
# # 最近出了一趟差,是从20号去的,今天回来... # 就把最近学习的python内容给大家分享一下... # ''' 在python中,configparser模块提供了操作*.ini配置文件的 ...
- python开发_gzip_压缩|解压缩gz文件_完整版_博主推荐
''' gzip -- 支持gzip文件 源文件:Lib/gzip.py 这个模块提供了一些简单的接口来对文件进行压缩和解压缩,类似于GNU项目的gzip和gunzip. 数据的压缩源于zlib模块的 ...
- 日常开发自己遇到异常(BUG未完待续!!!)
在面试的时候经常会被问到你在项目中遇到的bug有哪些,或者你感觉你解决什么问题让你感觉有成就感.以此类似的面试问答,楼主现在开始不断更新日常遇到的BUG汇总 1:ConcurentModificati ...
- Python基础:内置异常(未完待续)
本文根据Python 3.6.5的官文Built-in Exceptions编写,不会很详细,仅对Python的内置异常进行简单(重难点)介绍——很多异常都可以从名称判断出其意义,罗列所有的内置异常. ...
随机推荐
- vi中换行、翻页和查找功能
vi时,按ESC进入Command模式, 1. 移动光标命令:j 向下移动一行:k 向上移动一行:h 向左移动一个字符:l 向右移动一个字符:对于 j.k.l和h键,命令前加数字,移动多行:如 3j, ...
- 【HNOI 2018】道路
Problem Description \(W\) 国的交通呈一棵树的形状.\(W\) 国一共有\(n - 1\)个城市和\(n\)个乡村,其中城市从\(1\)到\(n - 1\) 编号,乡村从\(1 ...
- 洛谷 P1273 【有线电视网】
题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部节点. 从转播站到转播站以及从 ...
- JavaScript形而上的单例模式
什么是单例模式? 单例模式是指,类多次实例化返回的对象是同一个. 反例 var tt = function(name){ this.name = name; }; var t1 = new tt('t ...
- 微信小程序计算器模拟后续
今天按着自己的思路又重打了一遍 wxml没什么说的,就是分块起名,显示数字和结果的作为屏幕,数字键盘一行四块 <view class="onTop"> <view ...
- ckeditor5 安装高亮,颜色插件
ckeditor5 安装高亮插件 1.准备 git clone -b stable https://github.com/ckeditor/ckeditor5-build-classic.git cd ...
- Hibernate注意项
Hibernate实体规则 1.持久化类提供无参数构造 2.成员变量私有,提供getset访问,提供实行 3.持久化类属性,尽量使用包装类型 4.持久化类需要提供oid与数据库中的主键列对应 5.不要 ...
- MySQL中update修改数据与原数据相同会再次执行吗?
作者:powdba 来源:阿里云栖社区 一.背景 本文主要测试MySQL执行update语句时,针对与原数据(即未修改)相同的update语句会在MySQL内部重新执行吗? 二.测试环境 MySQL5 ...
- Idea搭建servlet开发过程
Idea搭建servlet开发过程 https://www.cnblogs.com/javabg/p/7976977.html (1) 安装idea,jdk,tomcat:设置好环境变量: (2 ...
- hdoj5754
题意:略 国王和骑士用记忆搜索,注意骑士的移动是x-2,y-1或x-1,y-2.车是NIM博弈,后是威佐夫博弈.注意威佐夫博弈中两堆石子有大小之分,而输入不一定小在前. #include <io ...
