Pythonx_day1
# python3中的 str 和 byte(即二进制)转换
msg = "β"
# 转换为二进制,打印,‘encoding = 'utf-8'为值定转换原str的编码格式’
print(msg.encode(encoding='utf-8'))
# 由二进制转回str编码
print(msg.encode(encoding='utf-8').decode(encoding='utf-8')) # 列表使用
city = ['Guangzhou', 'Shanghai','Beijing', 'Beijing', 'Tianjin']
print(city) # 列表元素可重复 # 列表的检索
city_1 = city[1]
print(city_1)
city_end = city[-1] # 可用来检索列表最后的元素
print(city_end)
#
# 列表的切片
city_z = city[0:2] # = city[:2] 注意打印出的为 0-1号的元素, 即‘顾头不顾尾’
print(city_z)
city_f = city[-4:-1] # = city[-4:] 反向序号切片 , 同时‘顾头不顾尾’--》‘顾左不顾右’
print(city_f)
city_t = city[0:-1:2] # 从开始到最后,每两个切一个元素。
print(city_t) # 将元素增加到列表中,加到最后
city.append('Hangzhou')
print(city) # 将指定元素插入到指定位置
city.insert(1,'Hangzhou')
print(city) # 移除 指定值 的元素
city.remove('Beijing')
print(city) city.pop() # .pop()方法默认删除列表末尾的元素,
city.pop(1) # .pop()方法,参数为1时,删掉序号为1的元素
print(city) # 删除指定序号位置的元素, del city[1] = city.pop(1)
del city[1]
print(city) # 更改指定位置元素的值
print(city)
city[1] = "Chongqing"
print(city) print(city.index("Tianjin")) # 查某元素在列表中对应的序号
print(city.count('Beijing')) # 检索所输入元素的的数量
city_c = city.clear()
print(city_c) # 清空列表 city.reverse() # 将列表元素反序
print(city)
city.sort() # 列表排序 一般顺序为 特殊字符》数字》大写字母》小写字母
print(city) # 列表扩展,将一个列表加入到另一个列表中
people = [111,112,113]
city.extend(people)
print(city)
# 删除列表
del people
print(people) # error: people not defined
Pythonx_day1的更多相关文章
随机推荐
- 分组后取每组内排名的Top N的SQL语句
给个MySQL例子参考 -----查询每门课程的前2名成绩 CREATE TABLE StudentGrade( stuId CHAR(4), --学号 subId I ...
- .net垃圾回收-原理浅析
本文引自:http://www.cnblogs.com/wilber2013/p/4357910.html 在开发.NET程序过程中,由于CLR中的垃圾回收(garbage collection)机制 ...
- Mysql表引擎的切换
转换MYSQL表的引擎 1.方法一:Alter table 将1个表的引擎修改为另一个引擎最简单的方法是使用Alter table语句. 下面的语句将myTable的引擎修改为InnoDB mysql ...
- js 40 个技巧
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键<table border oncontextmenu= ...
- mybastis_20190323
1 数据表 items.user.orders.orderdetail user id,username,birthday,sex,address; 使用原生态的jdbc的问题总结? 1 数据库链接问 ...
- swift中高阶函数map、flatMap、filter、reduce
Swift相比于Objective-C又一个重要的优点,它对函数式编程提供了很好的支持,Swift提供了map.filter.reduce这三个高阶函数作为对容器的支持. 1 map:可以对数组中的每 ...
- SpringCloud学习笔记(7)----Spring Cloud Netflix之负载均衡-Ribbon的深入理解
1. 注解@LoadBalanced 作用:识别应用名称,并进行负载均衡. 2. 入口类:LoadBalancerAutoConfiguration 说明:类头上的注解可以知道Ribbon 实现的负载 ...
- mysql 查询格式化时间
select DATE_FORMAT(addtime,'$m %d %Y') from tablename 输出:01 28 2019 数据库时间格式:2019-01-28 15:01:20
- 【BZOJ2006】【NOI2010】超级钢琴
题意: Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符 ...
- IIFE 萌新学习笔记
立即执行函数表达式(IIFE) IIFE:Immediately-Invoked Function Expression(立即执行函数表达式) 一 常用写法: //经常使用的写法(function() ...