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 ...
随机推荐
- 高德地图marker事件监听-高德地图marker绑定事件就执行了[解决立即执行]
官方的demo是这样的:地址:[http://lbs.amap.com/api/javascript-api/example/infowindow/add-infowindows-to-multipl ...
- 第六篇scrum冲刺
一. 站立式会议 1.会议照片 2. 项目进展 团队成员 昨日完成任务 今日计划任务 吴茂平 新消息提醒功能设计 实现开发新消息提醒功能 陈忠明 歌曲批量下载压缩包 歌手收藏功能 吴尚谦 设计下载 ...
- python列表的索引与切片
<1>.python的列表 索引方式: 例如,list1 = ['张三','男','33','江苏','硕士','已婚',['身高178','体重72']] 1.正向单索引 print(l ...
- 「Netty实战 02」手把手教你实现自己的第一个 Netty 应用!新手也能搞懂!
大家好,我是 「后端技术进阶」 作者,一个热爱技术的少年. 很多小伙伴搞不清楚为啥要学习 Netty ,今天这篇文章开始之前,简单说一下自己的看法: @ 目录 服务端 创建服务端 自定义服务端 Cha ...
- .Net MongoDB批量修改集合中子集合的字段
环境:.Net Core 3.1 (需要导入.Net MongoDB的驱动) 模型 /// <summary> /// 收藏 /// </summary> public cla ...
- elementUI的隐藏组件el-scroll--滚动条
由于原生的滚动条存在兼容性问题并且样式不是太美观,在项目中经常使用的是elementui,发现elementui中有个隐藏的组件,就是element官网使用的滚动条,可以优化滚动条样式.鼠标经过的时候 ...
- 细说强网杯Web辅助
本文首发于“合天智汇”公众号 作者:Ch3ng 这里就借由强网杯的一道题目“Web辅助”,来讲讲从构造POP链,字符串逃逸到最后获取flag的过程 题目源码 index.php 获取我们传入的user ...
- Asp.Net Core Swagger 接口分组(支持接口一对多暴露)
开始之前,先介绍下swagger常用方法. services.AddSwaggerGen //添加swagger中间件 c.SwaggerDoc //配置swagger文档,也就是右上角的下拉 ...
- lynx浏览器使用教程
http://www.wocaoseo.com/thread-216-1-1.html LYNX浏览器是谷歌官方推荐的一款文本浏览器,主要用来模拟蜘蛛看到您页面时候的样子,谷歌在网站站长指南中提到: ...
- CKA认证经验贴(认证日期:20200817)
一.背景 由于年初疫情影响,身处传统IT行业且兼职出差全国各地“救火”的我有幸被领导选中调研私有云平台,这就给我后来的认证之路做下了铺垫.之前调研kubernetes的v1.17版本自带kubeadm ...