整数和浮点(Python3 没有int和long只有int类型)

十进制 默认

二进制 0bnnn

八进制 0onnn

十六进制 0xnnn

float() decimal 固定小数模块

fractions有理分数

Bool类型 Ture False

bool()默认False

and or not 不支持xor

& l ^ ~(or)

<< >> 二进制移位

None 空对象(唯一的)

不可调用

容器內型

可迭代的类型

字符串 单重 双重 三重 引号

字符串不可变,基于当年字符串重新创建字符串,指向新的地址

uppper lower capitalize

center ljust rjust 对齐方式

startwith endwith

find index rfind

isalpha isdigit isalnum

join

split splitlines partition 分割

strip lstrip rstrip 出去指定字符默认除去空格,全局replace

replace

format

字节和字节数组

byte bytearry

1、列表、元组操作

定义列表list1=[]

list2=['a','bit','clor']

list3=[none]*5

列表的元素访问>>> list2=['a','bit','colr','doll','esr','fire']

>>> list2=['a','bit','colr','doll','esr','fire']

>>> list2[0]   #0为第一个

'a'

>>> list2[-1] #-1为倒数第一个

'fire'>>> list2[-2]

'esr'

>>> list2[0:] #0开始取完,由于是开区间,右边就不能写-1,不然取不完

['a', 'bit', 'colr', 'doll', 'esr', 'fire']

>>> list2[:-2] #第一个到倒数第二个,不包含倒数第二个,左闭右开的区间

['a', 'bit', 'colr', 'doll']

>>> list2[::2] #步长为2

['a', 'colr', 'esr']

基本方法:

增加

list.append()>>> list2.append('thisisappendin')

>>> list2

['a', 'bit', 'colr', 'doll', 'esr', 'fire', 'thisisappendin']

list.insert("positon",'')>>> list2.insert(2,'inse')

>>> list2

['a', 'bit', 'inse', 'colr', 'doll', 'esr', 'fire', 'thisisappendin']

删除

del list>>> del list2

>>> list2

Traceback (most recent call last):

File "", line 1, in

NameError: name 'list2' is not defined

>>> list2=['a', 'bit', 'inse', 'colr', 'doll', 'esr', 'fire', 'thisisappendin']

>>> del list2[2]

>>> list2

['a', 'bit', 'colr', 'doll', 'esr', 'fire', 'thisisappendin']

list.pop(下标)>>> list2.pop(2)     #不加位置参数,默认最后一个

'colr'

>>> list2

['a', 'bit', 'doll', 'esr', 'fire', 'thisisappendin']

list.remove('value')

>>> list2.remove('doll')

>>> list2

['a', 'bit', 'esr', 'fire', 'thisisappendin']

索引

list.index()   返回第一个匹配到的>>> list2

['a', 'bit', 'esr', 'fire', 'thisisappendin']

>>> list2.index('esr')

2

list.clear()>>> list1=[1,2,3,4,5,6]

>>> list2=['a','b','c','d','e']

>>> list3=list1

>>> list3

[1, 2, 3, 4, 5, 6]

>>> list3.clear

>>> list1

[1, 2, 7, 4, 5, 6]

list.sort() python3不支持同时有字符串和数字进行排序

list.reverse() 翻转

list.count("")

list.extend(list2)    把list2的内容扩展到list1

list.copy()   浅copy>>> list1=[1,2,3,45,6]

>>> list2=list1.copy()

>>> list2

[1, 2, 3, 45, 6]

>>> list2

[1, 2, 3, 45, 6]

>>> list1[2]=111

>>> list2

[1, 2, 3, 45, 6]

>>> del list1

>>> del list2

>>> list1=[[1,2,3,4],121,['a',1,'x'],{'x':20,'pm':15}]

>>> list2=list1.copy()

>>> list1[1]=12580

>>> list1

[[1, 2, 3, 4], 12580, ['a', 1, 'x'], {'pm': 15, 'x': 20}]

>>> list2

[[1, 2, 3, 4], 121, ['a', 1, 'x'], {'pm': 15, 'x': 20}]

>>> list1[0][2]=66

>>> list1

[[1, 2, 66, 4], 12580, ['a', 1, 'x'], {'pm': 15, 'x': 20}]

>>> list2

[[1, 2, 66, 4], 121, ['a', 1, 'x'], {'pm': 15, 'x': 20}]

浅copy只拷贝一层,只是复制一层值,而当这层值是一个引用时,复制的是引用,他们指向的同一个内存对象,这个对象并没有复制,这是后,修改其中一个另外一个也跟随改变

python各种数据类型的常用方法_python的基本数据类型:列表的方法相关推荐

  1. python 只取年月日 字符串_Python基础:数据类型和变量amp;字符串和编码

    Python基础:1.数据类型和变量 数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网 ...

  2. python数据类型怎么定义_Python的五大数据类型的作用、定义方式、使用方法

    一.简述Python的五大数据类型的作用.定义方式.使用方法: 1. 数字类型int: 1.整形 作用:可以表示人的年龄,身份证号码,身高和体重等 定义方式: weight = 130 print(w ...

  3. python如何读取字典的关键字_python提取字典key列表的方法

    python提取字典key列表的方法 更新时间:2015年07月11日 12:04:48 作者:企鹅不笨 这篇文章主要介绍了python提取字典key列表的方法,涉及Python中keys方法的使用技 ...

  4. python三元表达式求值_python 三元表达式的 列表推导式 生成器推导式

    python中三元表达式的语法如下 ===if else result = x if condition else y 另外一种三元表达式,比较少见 result = (x, y)[condition ...

  5. python微信好友_python 获取微信好友列表的方法(微信web)

    如下所示: import urllib import urllib2 import os import time import re import cookielib import xml.dom.m ...

  6. python字典转换为列表_Python中将字典转换为列表的方法

    说明:列表不可以转换为字典 ①转换后的列表为无序列表 a = {'a' : 1, 'b': 2, 'c' : 3} #字典中的key转换为列表 key_value = list(a.keys()) p ...

  7. python用post提交数据_python通过post提交数据的方法

    本文实例讲述了python通过post提交数据的方法.分享给大家供大家参考.具体实现方法如下: # -*- coding: cp936 -*- import urllib2 import urllib ...

  8. python字典嵌套字典构造_python实现字典嵌套列表取值

    python实现字典嵌套列表取值 如下所示: dict={'log_id': 5891599090191187877, 'result_num': 1, 'result': [{'probabilit ...

  9. python各种数据类型的常用方法_Python之数据类型的常用方法

    常用方法汇总 1. int类 方法汇总: 变量名.to_bytes('数字',"little"\"big") # (把数字转换成bytes) # 数字表示转换后 ...

最新文章

  1. jQuery-1.9.1源码分析系列(四) 缓存系统
  2. 列举窗体控制台应用程序中的3中控件_今天来点枯燥的,Visual C#的Windows窗体运行过程...
  3. JUnit5 快速指南
  4. Android killer软件闪退的解决办法?
  5. 微软发布Visual Studio 2012 示例代码浏览器
  6. scrapy学习笔记1---一个爬取的完整例子
  7. [Unity3d][NGUI]打包NGUI预制件成Assetbundle 两种思路.
  8. 无法安装冰点还原_系统还原软件介绍与功能
  9. Silvaco TCAD仿真10——MOSFET结构仿真
  10. xshell 6顶部工具栏找不到
  11. 配音是怎么制作出来的,想做出让人惊艳的配音,只需一个小技巧
  12. Easyconnect For Mac 最新版 下载地址
  13. ECharts天气预报折线图
  14. (读书笔记)中级语法-简单句和复杂句
  15. java酒店管理系统_java酒店管理系统(源码+数据库脚本)
  16. linux usb驱动——OTG数据线与普通数据线区别
  17. 总结!一个产品新手的踩坑记
  18. python用来初始化对象属性的是_猪行天下之Python基础——8.1 类与对象
  19. 解决安卓TV 应用图标不显示的问题
  20. 存储卡、逻辑加密卡和CPU卡的相关知识

热门文章

  1. Nginx的location指令
  2. kafka基本管理操作命令
  3. 缓存-分布式锁-缓存一致性解决
  4. 分布式文件系统研究-fastDSF架构介绍
  5. JAVA生成随机字符串方法
  6. css box 等高布局,css实现等高布局有哪些方式
  7. Spring Security OAuth2源码解析(一)
  8. 财政指标是什么意思_in the black是“在黑暗中”吗?那in the dark是什么意思?
  9. cuDNN error: CUDNN_STATUS_EXECUTION_FAILED
  10. 200726C的数据传递方式