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的更多相关文章
随机推荐
- WinForm关于listview的用法介绍
public Form1() { InitializeComponent(); //控件的行为 listView1.Bounds = , ), , ));//相对位置 listView1.View = ...
- Andoid CustomCircleProgress 半圆
package com.play.playgame.view; import android.content.Context; import android.graphics.Canvas; impo ...
- (转载)打开一个本地apk进行安装
1 2 3 4 5 6 Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); File file = new File ...
- (转载) Android RecyclerView 使用完全解析 体验艺术般的控件
Android RecyclerView 使用完全解析 体验艺术般的控件 标签: Recyclerviewpager瀑布流 2015-04-16 09:07 721474人阅读 评论(458) 收藏 ...
- 带参数,头信息,代理,cookie爬取
1.get传参 (1)汉字报错 :解释器器ascii没有汉字 url汉字转码 urllib.parse.quote safe="string.printtable" (2)字典传参 ...
- Visual Studio中C++工程的环境配置方法
在Visual Studio的C++工程设置 1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录. 2.添加文件引用的lib静态库路径:工程---属性- ...
- 利用php的GD库生成验证码
<?php ,); //创建一个100宽30高的底图,默认黑色 ,,); //修改颜色.数字对应 rgb 的三个数值.白色 imagefill(,,$bgcolor); //从左上角到右下角把颜 ...
- centos7 命令
firewall-cmd --zone=public --add-port=80/tcp --permanent 开启端口 systemctl stop firewalld.service 关闭服务 ...
- 1.1 Python for macOS 安装与配置
本文主要讲解在macOS系统下的Python3.7.0的配置与安装问题 并调试好开发环境 目标是编辑成功第一个python程序 下载最新版(3.7.0)Python macOS系统自带python 不 ...
- hdu 4841 圆桌问题(用vector模拟约瑟夫环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4841 圆桌问题 Time Limit: 3000/1000 MS (Java/Others) M ...