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-字符串,字典,列表的更多相关文章

  1. python字符串字典列表互转

    #-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...

  2. python字符串、列表和字典的说明

    python字符串.列表和字典的说明 字符串.列表.字典 字符串的作用存储一段数据信息.例如 info = '我爱北京天安门' ,在调取的时候可以直接调取,灵活方便,print(info) 就可以把刚 ...

  3. python字符串、列表和文件对象总结

    1.字符串是字符序列.字符串文字可以用单引号或者双引号分隔. 2.可以用内置的序列操作来处理字符串和列表:连接(+).重复(*).索引([]),切片([:])和长度(len()).可以用for循环遍历 ...

  4. python将字典列表导出为Excel文件的方法

    将如下的字典列表内容导出为Excel表格文件形式: ​ 关于上图字典列表的写入,请参考文章:https://blog.csdn.net/weixin_39082390/article/details/ ...

  5. python字符串、列表、字典的常用方法

    一.python字符串的处理方法 >>> str = ' linzhong LongXIA ' >>> str.upper() #字符串str全部大写 ' LINZ ...

  6. 【02】Python 字符串、列表、元组、字典

    1 列表 list就是一种采用分离式技术实现的动态顺序表(tuple也一样): 在建立空表(或者很小的表)时,系统分配一块能容纳8个元素的存储区: 在执行插入操作(insert或append)时,如果 ...

  7. python字符串/元组/列表/字典互转

    #-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...

  8. 转:python字符串/元组/列表/字典互转

    #-*-coding:utf-8-*-  #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...

  9. [python] 字符串与列表、字典的转换

    1.字符串->字典:eval(str) 2.字符串->列表:list(str)

  10. python 小白(无编程基础,无计算机基础)的开发之路,辅助知识6 python字符串/元组/列表/字典互转

    神奇的相互转换,小白同学可以看看,很有帮助 #1.字典dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...

随机推荐

  1. gpio模拟mdc/mdio通信

    本文主要是学习gpio模拟mdc/mdio通信. 运行环境是在ATMEL的sama5d35MCU,两个GPIO引脚模拟MDC/MDIO通信,读取百兆phy的寄存器的值. #include<lin ...

  2. 手机APP无法抓包(无法连接服务器)

    一. 把证书放到系统信任区 前提:手机已root 详细步骤 计算证书名 openssl x509 -subject_hash_old -in charles-ssl-proxying-certific ...

  3. golang []byte 和 string相互转换

    原文链接:golang []byte和string相互转换 测试例子 package main import ( "fmt" ) func main() { str2 := &qu ...

  4. Go interface 操作示例

    原文链接:Go interface操作示例 特点: 1. interface 是一种类型 interface 是一种具有一组方法的类型,这些方法定义了 interface 的行为.go 允许不带任何方 ...

  5. 操作系统-I/O(3)SPOOLing技术

    为了缓和CPU的高速性与I/O设备低速性间的矛盾而引入了脱机输入.输出技术.该技术是利用专门的外围控制机,将低速I/O设备上的数据传送到高速磁盘上:或者相反. 事实上,当系统中引入了多道程序技术后,完 ...

  6. Vue路由模块化的实现方法

    分享一个Vue路由模块化方法,简单实用,好用到飞起 路由模块化 1.router/index.js 配置路由 import Vue from 'vue' import VueRouter from ' ...

  7. 区块链入门到实战(27)之以太坊(Ethereum) – 智能合约开发

    智能合约的优点 与传统合同相比,智能合约有一些显著优点: 不需要中间人 费用低 代码就是规则 区块链网络中有多个备份,不用担心丢失 避免人工错误 无需信任,就可履行协议 匿名履行协议 以太坊(Ethe ...

  8. 外贸网站SEO优化哪家公司好

    http://www.wocaoseo.com/thread-98-1-1.html        随着b2c的崛起,越来越多的企业已经放弃挂在第三方面台销售,而是选择去建独立的商场,拥有一个属于自已 ...

  9. Azure Storage 系列(一)入门简介

    一,引言 今天作为新的Azure 资源介绍的开篇,我们来学习一个新的服务,Azure Storage.众所周知,我们实际在开发过程中,会需要存储一些比如说日志,图片,等等,各种类型的数据.比如说存储图 ...

  10. Ignatius and the Princess IV (水题)

    "OK, you are not too bad, em... But you can never pass the next test." feng5166 says.  &qu ...