一、昨日内容回顾

  • Python种类:CPython(Python)、JPython、IronPython、PyPy
  • 编码: Unicode、UTF-8、GBK
  • while循环
  • if...elif...else条件控制

###二、运算符
1.**算数运算**
> ```+``` ```-``` ```*``` ```**```这些基本的运算符就不需要再重复了,需要注意的是以下几个运算符的用法:

	/       除法
% 取模(取余)
// 除法取整

2.成员运算

	in          包含
not in 不包含

3.比较运算

	==    比较值
is 比较来源(是否来自同一块内存空间)

4.**逻辑运算**
> 运算顺序为:
>
> - 先计算()内的
> - 从前到后
> - True or == True (不论or后面是什么,因为前面是True,运算结果都会是True)
> - False and == False (不论and后面是什么,前面是False,运算结果都会是False)

三、数据类型与内建函数

1.整型 int

int('x', base=n)             将string转化为n进制的integer(仅限全为数字的字符串)
integer.bit_length() 整型二进制位数(至少)
abs(x)
ceil(x)
cmp(x, y)
exp(x)
fabs(x)
floor(x)
log(x)
log10(x)
max(x1, x2, ...)
min(x1, x2, ...)
modf(x)
pow(x, y)
round(x[,n])#################
aqrt(x)

2.**字符型 str**

string.bit_length()           字节数
string.upper() 转换为大写
string.lower() 转换为小写(仅英文)
string.casefold() 转换为小写(各种文)
string.capitalize() 首字母大写
string.center(n, '-') 行宽n,string居中,字符'-'占位
string.ljust(n, '-') 内容置左,右侧以'-'填充至宽度为n
string.rjust(n, '-') 内容置右,左侧以'-'填充至宽度为n
string.zfill(n) 内容置右,以'0'填充至宽度为n
string.count('s', n, m) 计算's'在位置n~m间出现次数
string.endswith('s') 以's'结尾,rtype:boolen
string.startswith('s') 以's'起始,rtype:boolen
string.expandtabs(n) 将string以n分组,遇到\t以空格补位,可用于格式化输出(表格形)
string.find('s',n, m) 在n~m位置之间,查找's'第一次出现的位置,不存在返回-1
string.format('') 格式化,配合n='{var}'或n ='{0}',将字符串中的占位符按顺序替换为指定内容
string.format_map({'var':'',})格式化,参数为dict类型
string.index() 找到位置,不存在报错(不用)
string.isalnum() 仅包含数字、字母,rtype:boolen
string.isalpha() 是否全为字母,rtype:boolen
string.isdigit() 是否全为数字(各种类型的数字,不包括中文,最常用)
string.isdecimal() 是否全为数字(仅十进制数)
string.numeric() 是否全为数字(支持中文)
string.isidentifier() 是否可以作为标识符(变量命名规则)
string.islower() 是否全为小写
string.lower() 转换为小写
string.isupper() 是否全为大写
string.upper() 转换为大写
string.isprintable() 是否存在打印时不可显示的字符(如\t\n),rtype:boolean
string.isspace() 是否全为空格,rtype:boolean
string.istitle() 是否为标题(每个单词首字母大写)
string.title() 转换为标题
'-'.join(string) 使用'-'对string中的字符进行拼接
string.lstrip() 移除string左侧的指定字符包含的最长公共子序列(默认移除空字符)
string.rstrip() 移除string右侧的指定字符包含的最长公共子序列(默认移除空字符)
string.strip() 移除string两侧的指定字符包含的最长公共子序列(默认移除空字符)
string.maketrans(s1, s2) 建立s1 s2对应关系
string.translate(m) 根据m的对应关系对string中的字符进行替换
string.partition('s') 以第一次遇到的's'对string进行分割,保留's'
string.rpartition() 从右侧起进行partition()操作
string.split('s', n) 以's'对string进行n次分割,不保留's'
string.rsplit() 从右侧起进行split()操作
string.splitlines(True) 根据\n对string进行分割,True/False指定保留/不保留
string.swapcase() 大小写互换
string.replace(old, new, n) 将string中old替换为new,执行n次

len() Python3:中文按字符计算 Python2:中文按字节计算

支持切片

支持遍历

字符串不可修改,只能重新创建

range(n, m, s) n: 起始值 m: 结束值 s: 步长

3.**列表 list**

list()                        转换为list类型(支持字符串)
list.append(item) 将item追加至list中
list.clear() 清空列表
list.copy() 浅拷贝
list.count(item) 统计item的个数
list.extend(iterable) 扩展list(将可迭代对象的元素追加至list)
list.index(var,n,m) 在位置n,m间查询var的索引(只找到第一个返回)
list.insert(idx,item) 插入元素item到idx(索引号)位置
list.pop(idx) 弹出指定位置的值并返回(无参数默认返回最后一个元素)
list.remove(var) 删除指定值(有重复删除左侧第一个)
list.reverse() 反转列表
list.sort(reverse=True) 排序(True由大到小,False从小到大,不写参数默认从小到大)
del li[n:m] 删除元素(根据索引)
''.join() 将列表元素拼接为字符串(元素需全为字符串)

可迭代,支持切片

深拷贝deepcopy)与 浅拷贝copy

有序,元素 可以被修改

4.元组 tuple

tu = ('a', 'b',)  #建议末尾多加个```,```以明显区分函数和元组尾部  

tuple.count(item)            统计指定item出现的次数
tuple.index(item) 获取item的索引(重复取左一)

一级元素不可增加、修改、删除

可迭代

有序

5.字典 dict

{key: value} # key可以是 int、string、tuple、boolean(但要注意,布尔型与其他类型布尔值的对应关系(下文讲布尔型时会说到),同为False或True则不可并存

for k, v in dict.items():    遍历键值对
for key in dict: 遍历键
for value in dict.values(): 遍历值 del dict[key] 删除key及对应的值
dict.clear()
dict.copy()
# 静态方法dict为类名
dict.fromkeys(keys, values) 根据序列创建字典,并指定统一的values,keys为可迭代对象
dict.get(key, rvalue) 根据key获取值,key不存在时返回rvalue(不写为None)
dict.pop(key,rvalue) 弹出键及对应值,
dict.popitem() 随机弹出键值对,rtype:tuple
dict.setdefult(key,value) 设置值,若key存在,获取并返回对应值;若key不存在,设置并返回设置的值
dict.update()

支持for遍历

6.布尔型 bool

布尔值:TrueFalse

数字:0False其他 均为 True

字符:空值 均为 False,非空值 均为 True

Python--Day2/Day3/Day4(运算符、数据类型及内建函数)的更多相关文章

  1. 跟着ALEX 学python day2 基础2 模块 数据类型 运算符 列表 元组 字典 字符串的常用操作

    声明 : 文档内容学习于 http://www.cnblogs.com/xiaozhiqi/  模块初始: Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相 ...

  2. Python编程Day3—基本运算符、数据类型

    一.基本运算符 1.算数运算 print(10/3) print(10//3) print(10%3) print(10**3) 2.比较运算 print(10==10) print(10!=10) ...

  3. python day2:python的基本数据类型及其方法

    目录 python day2 1. 编码转换 2. python的基本数据类型 3. for 迭代遍历 4. 列表list 5. 元组tuple 6. 字典dict 7. 枚举enumerate 8. ...

  4. Python学习笔记:02数据类型

    Python 数据类型 python中标准的数据类型有 基础类型 整型(长整型) 浮点型 复数型 布尔型 序列类型 字符串 列表 元组 字典 整型 整型和长整型并不严格区分,整型int的表达范围和计算 ...

  5. python学习笔记之运算符

    目录 前言 软件环境 身份运算符 算术运算符 比较运算符 位移运算符 自变运算符 位运算符 逻辑运算符 成员关系运算符 Python真值表 最后 前言 在前面的博文介绍了Python的数据结构之后,接 ...

  6. Python基本语法_运算符详解

    目录 目录 前言 软件环境 身份运算符 算术运算符 比较运算符 位移运算符 自变运算符 位运算符 逻辑运算符 成员关系运算符 Python真值表 最后 前言 在前面的博文介绍了Python的数据结构之 ...

  7. python笔记 - day3

    python笔记 - day3 参考:http://www.cnblogs.com/wupeiqi/articles/5453708.html set特性: 1.无序 2.不重复 3.可嵌套 函数: ...

  8. Python之路,Day4 - Python基础4 (new版)

    Python之路,Day4 - Python基础4 (new版)   本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...

  9. Python自动化开发-变量、数据类型和运算

    一.变量 变量定义:Variables are used to store infomation to referrenced and manipulated in a computer progra ...

随机推荐

  1. “帮你APP”团队冲刺5

    1.整个项目预期的任务量 (任务量 = 所有工作的预期时间)和 目前已经花的时间 (所有记录的 ‘已经花费的时间’),还剩余的时间(所有工作的 ‘剩余时间’) : 所有工作的预期时间:88h 目前已经 ...

  2. RF,GBDT,XGBoost,lightGBM的对比

    转载地址:https://blog.csdn.net/u014248127/article/details/79015803 RF,GBDT,XGBoost,lightGBM都属于集成学习(Ensem ...

  3. 配置网络策略中的 NAP 条件

    TechNet 库 Windows Server Windows Server 2008 R2 und Windows Server 2008 按类别提供的 Windows Server 内容 Win ...

  4. leetcode 【 Trapping Rain Water 】python 实现

    题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...

  5. Memcached相关内容总结

    1.Memcached常用命令总结 Memcached命令格式一般为: command 其中描述如下: 参数 描述 command 操作命令,一般为set/add/replace/get/delete ...

  6. 设计模式之责任链模式 chainOfResp

    后面我们将学习设计模式里面的行为型模式 代码实现 /** * 抽象类 * @author bzhx * 2017年3月14日 */ public abstract class Leader { pro ...

  7. [转]核函数K(kernel function)

    1 核函数K(kernel function)定义 核函数K(kernel function)就是指K(x, y) = <f(x), f(y)>,其中x和y是n维的输入值,f(·) 是从n ...

  8. 链表的问题,ListNode问题

    算法面试,有关ListNode的问题 class ListNode{ ListNode *next; int val; ListNode(int x): val(x){}}; 在面试的时候,怎么快速想 ...

  9. jira从windows迁移到linux

    说明:迁移的就是 jira安装路径/atlassian/jira/atlassian-jira/WEB-INF/classes/jira-application.properties文件中的jira_ ...

  10. ACdream 1738 世风日下的哗啦啦族I(分块大法+二分)

    世风日下的哗啦啦族I Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit S ...