Build-in Function:abs(),all(),any(),assii(),bin(),issubclass(),bytearray(),isinstance()
- print('abs():输出绝对值,是absolute的缩写--------------')
- print(abs(-1))
- print('all()与any()---------------------------')
- #all都为真时才为真,但是空的为真,any()有一个为真时就是真的
- jo1_list=[1,2,3,4,5,6,7]
- jo2_list=['',2,3,4,5,7]
- jo4_list=[0,2,3,4,5,6,7]
- jo5_list=[False,2,3,4,5,6,7]
- jo6_list=[]
- jo7_list=[0,'',False]
- print('all()列表元素不为空和零',all(jo1_list))
- print('all()列表元素包含一个空',all(jo2_list))
- print('all()列表元素包含一个0',all(jo4_list))
- print('all()列表元素包含一个False',all(jo5_list))
- print('all()列表元素为空',all(jo6_list))
- print('all()列表元素为空、零和假',all(jo7_list))
- print('any()列表元素不为空和零',any(jo1_list))
- print('any()列表元素包含一个空',any(jo2_list))
- print('any()列表元素包含一个0',any(jo4_list))
- print('any()列表元素包含一个False',any(jo5_list))
- print('any()列表元素为空',any(jo6_list))
- print('all()列表元素为空、零和假',any(jo7_list))
- print('ascii()-----------------------')
- print('参数为数字,返回字符串',ascii(10))
- print('参数为字符串,返回字符串',ascii('jojojo'))
- print('参数为汉字,返回字符串',ascii('呵呵哒'))
- print('bin()是binary的缩写--------------------------')
- print(bin(1))
- print(bin(10000**1000))
- print('bool()---------')
- print(bool())
- print(bool(0))
- print(bool(1))
- print(bool(2))
- print('issubclass()---')
- class jo:
- pass
- class joo(jo):
- pass
- class jook:
- pass
- print(issubclass(joo,jo))
- print(issubclass(jook,jo))
- >>>> bytearray('heheda')
- Traceback (most recent call last):
- File "<pyshell#28>", line 1, in <module>
- bytearray('heheda')
- TypeError: string argument without an encoding
- >>> bytearray(heheda)
- Traceback (most recent call last):
- File "<pyshell#29>", line 1, in <module>
- bytearray(heheda)
- NameError: name 'heheda' is not defined
- >>> bytearray('heheda',''utf-8)
- SyntaxError: invalid syntax
- >>> bytearray('heheda','utf-8')
- bytearray(b'heheda')
- >>> bytearray('heheda','gb2312')
- bytearray(b'heheda')
- >>> bytearray('heheda','BIG5')
- bytearray(b'heheda')
- >>> bytearray('呵呵哒','BIG5')
- Traceback (most recent call last):
- File "<pyshell#34>", line 1, in <module>
- bytearray('呵呵哒','BIG5')
- UnicodeEncodeError: 'big5' codec can't encode character '\u54d2' in position 2: illegal multibyte sequence
- >>> bytearray('呵呵哒','gb2312')
- bytearray(b'\xba\xc7\xba\xc7\xdf\xd5')
- >>> bytearray('呵呵哒','utf-8')
- bytearray(b'\xe5\x91\xb5\xe5\x91\xb5\xe5\x93\x92')
- >>> is
- SyntaxError: invalid syntax
- >>> isinstance(jojo,str)
- Traceback (most recent call last):
- File "<pyshell#38>", line 1, in <module>
- isinstance(jojo,str)
- NameError: name 'jojo' is not defined
- >>> isinstance('jojo',str)
- True
- >>> isinstance('jojo',unicode)
- Traceback (most recent call last):
- File "<pyshell#40>", line 1, in <module>
- isinstance('jojo',unicode)
- NameError: name 'unicode' is not defined
- >>> isinstance('jojo','utf-8')
- Traceback (most recent call last):
- File "<pyshell#41>", line 1, in <module>
- isinstance('jojo','utf-8')
- TypeError: isinstance() arg 2 must be a type or tuple of types
- >>> isinstance('jojo','utf-8')
Build-in Function:abs(),all(),any(),assii(),bin(),issubclass(),bytearray(),isinstance()的更多相关文章
- Python的内置方法,abs,all,any,basestring,bin,bool,bytearray,callable,chr,cmp,complex,divmod
Python的内置方法 abs(X):返回一个数的绝对值,X可以是一个整数,长整型,或者浮点数,如果X是一个复数,此方法返回此复数的绝对值(此复数与它的共轭复数的乘积的平方根) >>> ...
- the simmon effect(in psychology) :build the function of subject_information(modify the experiment programme),before we begin the experiment
#the real experiment for simon effect #load the library which is our need import pygame import sys i ...
- simon effect (psychology experiment ) : build the function of wait4key()
## #the real experiment for simon effect #load the library which is our need import pygame import sy ...
- Python3语法详解
一.下载安装 1.1Python下载 Python官网:https://www.python.org/ 1.2Python安装 1.2.1 Linux 平台安装 以下为在Unix & Linu ...
- 初始python第三天(三)
全局变量与局部变量 1.什么是全局变量 在globals中的变量,都是全局变量,全局变量的作用域就是整个程序 NAME = 'alex' def global_test(): name = 'alex ...
- Python-3 语法
#1 Tab键: 1)控制缩进 2)IDLE智能补全 #2 =等号: 1)=:表示赋值 2)==:表示判断 #3 流程图: print('..........小甲鱼_1..........') tem ...
- Python模块学习
6. Modules If you quit from the Python interpreter and enter it again, the definitions you have made ...
- 【Python 函数对象 命名空间与作用域 闭包函数 装饰器 迭代器 内置函数】
一.函数对象 函数(Function)作为程序语言中不可或缺的一部分,但函数作为第一类对象(First-Class Object)却是 Python 函数的一大特性. 那到底什么是第一类对象(Firs ...
- 【python】BIF及查看函数帮助
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32 Type ...
随机推荐
- jquery.peity.js简介
jQuery简单图表peity.js <html xmlns="http://www.w3.org/1999/xhtml"> <head> <titl ...
- css3整理--word-wrap/word-break/white-space
word-wrap语法: word-wrap : normal | break-word normal : 默认值,单词如果单词超长,会冲出边界(单个单词超长,在当前行显示) break-word : ...
- jQuery队列(一)
jQuery的队列依赖缓存机制事件,它同时是animate的基础. 它不像事件机制.缓存机制.回调机制一样有自己的命名空间,由于比较简单,所以直接挂在到$和jQuery对象上. 它提供的基础方法有: ...
- css修改select默认样式
先来看看效果图: css: <style media="screen"> .select_demo, .select_list { width: 400px; heig ...
- redmine创建新闻,自动发邮件给项目组所有成员
redmine创建新闻,自动发邮件给项目组所有成员: 1.添加用户至公共项目内 2.配置系统邮件推送配置 3.检查用户接受推送配置 3.使用管理员账户发布新闻(不能自己发送自己) 4.查看邮件接受邮件
- 慕课网,vue高仿饿了吗ASP源码视频笔记
1.源码笔记 我的源码+笔记(很重要):http://pan.baidu.com/s/1geI4i2Z 感谢麦子学院项目相关视频 2.参考资料 Vue.js官网(https://vuejs.org.c ...
- Python数据分析必备Anaconda安装、快捷键、包安装
Python数据分析必备: 1.Anaconda操作 Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便 ...
- PAT-GPLT L1-039 - 古风排版 - [字符串输入输出]
题目链接:https://www.patest.cn/contests/gplt/L1-039 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standar ...
- pycurl实例详解
Pycurl是Python的libcurl接口.liburl是客户端的URL传输库,它支持FTP,FTPS,HTTP,HTTPS,TELNET,LDAP等诸多协议,同时支持HTTP认证,代理,FTP上 ...
- 替换{0}为指定的字符串(MessageFormat)
package com.text; import java.text.MessageFormat; /**替换{0}为指定的字符串*/ public class MessageFormatTest { ...