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 ...
随机推荐
- Java之reflection(反射机制)——通过反射操作泛型,注解
一.反射操作泛型(Generic) Java采用泛型擦除机制来引入泛型.Java中的泛型仅仅是给编译器Javac使用的,确保数据的安全性和免去强制类型转换的麻烦.但是编译一旦完成,所有和泛型有关的类型 ...
- Ubutun重启网卡
一.network利用root帐户# service networking restart 或者/etc/init.d/networking restart 二.ifdown/ifup# ifdown ...
- 从一个小需求感受Redis的独特魅力
分享一个简单的小需求应该怎么设计实现以及有关Redis的使用 Redis在实际应用中使用的非常广泛,本篇文章就从一个简单的需求说起,为你讲述一个需求是如何从头到尾开始做的,又是如何一步步完善的. 需求 ...
- 从Vessel到二代裸金属容器,云原生的新一波技术浪潮涌向何处?
摘要:云原生大势,深度解读华为云四大容器解决方案如何加速技术产业融合. 云原生,可能是这两年云服务领域最火的词. 相较于传统的应用架构,云原生构建应用简便快捷,部署应用轻松自如.运行应用按需伸缩,是企 ...
- vue项目在执行npm install时报错
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning ETIMEDOU ...
- PHP - 读取EXCEL内容 存入数据库
<?php //设置请求头 header("Content-Type:text/html;charset=utf8"); header("Access-Contro ...
- Codeforces1247D Power Products 暴力+优化
题意 给定数组\(a(\left| a \right|\leq 10^5)\)和整数\(k(2\leq k \leq 100)\),问满足一下条件的二元组\(<i,j>\)的数目: \(1 ...
- js map对象处理if
onButtonClick只有一个参数时候,map和object对象都可以 // onButtonClick1(3) onButtonClick只有一个参数时候,map和object对象都可以 con ...
- VMware中卸载安装Ubuntu系统 ——Ubuntu系统配置(一)
由于之前配置给Ubuntu的磁盘空间不足,进行了扩展磁盘空间,结果Ubuntu无法开机了,试了很多种办法都没成功,也有些后悔没有记录下配置过程,于是决定卸载Ubuntu进行重新安装和配置. 一.VMw ...
- Layui + tp3.2 配合表格搜索
html 部分 <!--搜索--><fieldset class="layui-elem-field layui-field-title" style=" ...