# 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的更多相关文章

随机推荐

  1. Java中如何解决线程安全问题

    给出一个问题,如下: 解决方案如下: public class Demo_5 { public static void main(String[] args) { //创建一个窗口 TicketWin ...

  2. 使用xshell连接本地虚拟机中的Linux问题

    xshell 连接虚拟机中Linux报错: Could not connect to '192.168.8.120' (port 22):Connection failed. 原因:虚拟机中Linux ...

  3. JDOJ 2785: 商之和 数论分块

    Code: #include <iostream> #include <cstdio> #define setIO(s) freopen(s".in",&q ...

  4. Unable to load annotation processor factory

    很多人在项目开发中都会遇到项目名称左上角有个红叉,有些是Jar问题,有些是代码问题,有些是编译问题,对于我这种强迫症的是受不了这种情况发生的,如果不影响项目启动还好,废话少说,今天工作就出现了一个问题 ...

  5. React 第三天

    第三天 01:在组件中使用style行内对象并封装样式对象: CmtItem.jsx: import React from 'react' //第一层封装 将样式对象和UI结构分离 // const ...

  6. php xml 的基本操作类

    class xmlMessage{ protected $doc; protected $rootKey; public function __construct() { $this->doc ...

  7. POJ-3159 Candies 最短路应用(差分约束)

    题目链接:https://cn.vjudge.net/problem/POJ-3159 题意 给出一组不等式 求第一个变量和最后一个变量可能的最大差值 数据保证有解 思路 一个不等式a-b<=c ...

  8. Django模版系统

    一.什么是模板? 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板. 二.模板语法分类 一.模板语法之变量:语法为 {{ }}: 在 Django 模板中遍历复杂数据结构的关键 ...

  9. [USACO4.1]篱笆回路Fence Loops

    题目:USACO Training 4.1(在官网上提交需加文件输入输出).洛谷P2738. 题目大意:给你一张图里的边集,让你求出这张图的最小环. 解题思路:求最小环很简单,用Floyd即可.最重要 ...

  10. LibSVM C/C++

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50179779 在LibSVM的库的sv ...