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的更多相关文章
随机推荐
- FCC高级编程之Inventory Update
Inventory Update Compare and update the inventory stored in a 2D array against a second 2D array of ...
- mysql插入数据出现java.lang.NullPointerException
在写购物车持久层的时候,要进行测试的时候居然出现了空指针异常: 最后发现是测试类少了 @RunWith(SpringRunner.class)@SpringBootTest 如下是没改之前的测试类: ...
- npm包的上传npm包的步骤,与更新和下载步骤
官网: ======================================================= 没有账号可以先注册一个,右上角点击“Sign Up",有账号直接点击“ ...
- [HEOI2012]采花(树状数组+离线)
听说这题的所发和HH的项链很像. 然而那道题我使用莫队写的... 这是一个套路,pre数组加升维(在线). 记录一个\(pre\)数组,\(pre[i]\)代表上一个和i颜色相同的下标. 我们把询问离 ...
- react-native 运行提示红屏 error: bundling failed: ambiguous resolution: module `/User/xxx/Project/ico/index.js` tries to require `react-native`, but there are several files providing this module. You can de
运行 react-native start 报错 执行这2个进行清除缓存问题 yarn start -- --reset-cache npm start -- --reset-cache
- 关于数组array_diff(array1, array2)求差集来比较数组是否相等的问题细究
无意中发现很多朋友都喜欢使用array_diff(array1, array2)来判断两个数组是否相等, 我自己也偶尔会这么使用 但是今天我在写代码的过程中无意发现这么做是不准确的. 首先我们来看一下 ...
- mysql死锁-查询锁表进程-分析锁表原因
查询锁表进程: 1.查询是否锁表 show OPEN TABLES where In_use > 0; 2.查询进程 show processlist 查询到相对应的进程===然 ...
- Node.js使用cnpm
npm是Node.js中维护第三方库.模块的工具,可是国外的速度非常悲剧,这里有一个中国的源cnpm. http://cnpmjs.org/ 须要在命令行中执行 npm install -g cnpm ...
- hadoop-03-安装java
hadoop-03-安装java 1,su root 2, rpm -qa|grep jdk #查看已经安装的jdk 3,rpm -e --nodeps `rpm -qa|grep jdk ` #删除 ...
- Java IO(二) 之 InputStream
源代码均以JDK1.8作为參考 前言: InputStream实现了两个接口Closeable和AutoCloseable: Closeable:JDK1.5中引入,Closeable接口中仅仅有一个 ...