python-字符串,字典,列表
0x01 字符串
python单双引号都可以
str = "hello world"
str_test = "yicunyiye"
print(str,str_test)
注释
#单行注释
"""
多行注释
"""
input你输入了任何东西都强转成字符串输出
str = "hello world"
str_test = "yicunyiye"
print(str,str_test)
print("hello \n world")
print(str_test+"\n"+str)
print("\t hello")
print("'")
print('"')
input_test = input('>>>')
print("你输入了:",input_test)
也可以c语言风格
intTest = 1234
print("int is %d"%intTest)
%r原本替换
rtest = '"123'
print("your input is %r"%rtest)
输出
your input is '"123'
使用terminal
from sys import argv
print('你输入的参数是:%r'%argv)
from sys import argv
print('你输入的参数是:%r'%argv[1])
在terminal中输入
python StringTest.py yicunyiye
输出
你输入的参数是:['StringTest.py', 'yicunyiye']
你输入的参数是:'yicunyiye'
0x02 列表
列表
split
序号切片
pop
append
len
remove
strTest = '1 2 3 4 5 6'
print(strTest.split(' '))
输出
['1', '2', '3', '4', '5', '6']
增删改查
1.添加
listTest.append("yicunyiye")
print(listTest)
输出
[1, 2, 3, 4, 5, 'yicunyiye']
2.弹出
print(listTest.pop())
输出
yicunyiye
原列表就没有yicunyiye了,相当于删除表尾元素
删除,写3就是删除3写'a'就是删除a
listTest = [1,2,'a',4,5]
listTest.remove('a')
print(listTest)
输出
[1, 2, 4, 5]
列表是从0开始的
print(listTest[0])
输出1
listTest = [1,2,4,5]
print(listTest[1:3])
输出[2, 4]
可以知道左闭右合
计算列表长度
print(len(listTest))
0x03 字典
增加
查找
删除
改变
取出所有
#键 值 对
dictTest = {"one":"yicunyiye","two":"wutang"}
print(dictTest)
输出
{'one': 'yicunyiye', 'two': 'wutang'}
增加
#增加
dictTest["three"] = "keji"
print(dictTest)
输出
{'one': 'yicunyiye', 'two': 'wutang', 'three': 'keji'}
删除
#删除
del dictTest["three"]
#dictTest.pop("two")
print(dictTest)
输出
{'one': 'yicunyiye', 'two': 'wutang'}
改变
#改变
dictTest["two"] = "yicunyiye"
print(dictTest)
输出
{'one': 'yicunyiye', 'two': 'yicunyiye'}
查找
#查找
print(dictTest["one"])
print(dictTest.get("two"))
输出
yicunyiye
取出所有
#取出所有
print(dictTest.items())
输出
dict_items([('one', 'yicunyiye'), ('two', 'yicunyiye')])
复制
#复制
newDict = dictTest.copy()
print(newDict)
输出
{'one': 'yicunyiye', 'two': 'yicunyiye'}
python-字符串,字典,列表的更多相关文章
- python字符串字典列表互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...
- python字符串、列表和字典的说明
python字符串.列表和字典的说明 字符串.列表.字典 字符串的作用存储一段数据信息.例如 info = '我爱北京天安门' ,在调取的时候可以直接调取,灵活方便,print(info) 就可以把刚 ...
- python字符串、列表和文件对象总结
1.字符串是字符序列.字符串文字可以用单引号或者双引号分隔. 2.可以用内置的序列操作来处理字符串和列表:连接(+).重复(*).索引([]),切片([:])和长度(len()).可以用for循环遍历 ...
- python将字典列表导出为Excel文件的方法
将如下的字典列表内容导出为Excel表格文件形式: 关于上图字典列表的写入,请参考文章:https://blog.csdn.net/weixin_39082390/article/details/ ...
- python字符串、列表、字典的常用方法
一.python字符串的处理方法 >>> str = ' linzhong LongXIA ' >>> str.upper() #字符串str全部大写 ' LINZ ...
- 【02】Python 字符串、列表、元组、字典
1 列表 list就是一种采用分离式技术实现的动态顺序表(tuple也一样): 在建立空表(或者很小的表)时,系统分配一块能容纳8个元素的存储区: 在执行插入操作(insert或append)时,如果 ...
- python字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...
- 转:python字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...
- [python] 字符串与列表、字典的转换
1.字符串->字典:eval(str) 2.字符串->列表:list(str)
- python 小白(无编程基础,无计算机基础)的开发之路,辅助知识6 python字符串/元组/列表/字典互转
神奇的相互转换,小白同学可以看看,很有帮助 #1.字典dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...
随机推荐
- 什么情况下适合用UDP协议,什么情况下适合用TCP协议?
总的来说 TCP协议提供可靠的服务, UDP协议提供高效率的服务. 高可靠性的TCP服务提供面向连接的服务,主要用于一次传输大量报文的情形, 如文件传输,远程登录等: 高效率的UDP协议提供无连接的数 ...
- Magento 2 instantiate object by Factory Objects
magento2的Factory Objects是用来实例化non-injectable classes,目前还不知道什么叫non-injectable classes. 可以用它来实例化Helper ...
- python3在科学计算中的三种常用数据结构
在科学研究中,数据运算是必不可少的,下面介绍python语言在科学计算中常用的数据结构和运算函数. 主要数据结构: (1)列表,用中括号表示,元素之间逗号分隔,每个元素可以是数字,字符,也可以是列表, ...
- PHP、JS一些用法
PHP去除小数点后面的0,保留非零 floatval($num) PHP转数组var d = eval(数组d); PHP字符串转数组 $row['0'] = explode(";" ...
- 2020.5.23 第三篇 Scrum冲刺博客
Team:银河超级无敌舰队 Project:招新通 项目冲刺集合贴:链接 目录 一.每日站立会议 二.项目燃尽图 三.签入记录 3.1 代码/文档签入记录 3.2 主要代码截图 3.3 程序运行截图 ...
- 简述HBase的Bulk Load
为什么用Bulk load? 批量加载数据到HBase集群,有很多种方式,比如利用 HBase API 进行批量写入数据.使用Sqoop工具批量导数到HBase集群.使用MapReduce批量导入等等 ...
- Vue基础(一)---- 模板语法
1.基本理解 Vue其实是一个渐进式JavaScript框架,封装好了一些方法,不再需要操作通过操作DOM,在相同的目标下能够更快的编写代码. 声明式渲染→组件系统→客户端路由→集中式状态管理→项目构 ...
- MyTerm入选北极代码库计划,喜获「Arctic Code Vault Contributor」勋章
- Excel-时间函数将时间换成小时
问题场景 用考勤打卡时间算员工饱和度. 场景 计算员工实际工作时长,需要算出打卡时长再减去午休时长1.5小时. 目标 算出实际工作时长. 解决方案 利用单元格格式设置进行简单计算. 第一步:在F2单元 ...
- libtorrent资料整理
源码libtorrent源码地址:https://github.com/arvidn/libtorrent/releases libtorrent Java库地址:https://github.com ...