数组

a = [1,2,3]
print(a)

数组替换

a = [1,2,3]
a[0] = 100
print(a)

数组去重复

def delete_chong():
a = [1,1,2,2,3]
b = []# 建立一个空数组
for i in a:
if i not in b : # 如果a数组中的元素,b中没有
b.append(i)# 将该元素放进b中
print(b)
delete_chong()

再数组的末尾加上一个数字

a = [1,2,3]
a.append(100)
print(a)

删除指定位置的元素

a = [1,1,1,3,3,3]
a.remove(4)
print(a)

在数组中指定位置插入数字

a = [1,2,3,4]
a.insert(1,400)
print(a)

数组中元素交换位置

a = [2,1,3,4,10]
a[3],a[4] = a[4],a[3] #将指针为3和4位置的数字调换
print(a)

数组内容

数组里什么都能放

m = [1,1.0,'a',print,str,[10,20,[33,44]]]
print(m)

列表生成式

  简单的来说就是使用for循环来生成一个简单列表,复杂一些的貌似写不出来

占用内存较多

f = [x for x in range(11)] # 简写的for循环,列表生成式
# f = [x for x in range(11) if x % 2 == 0]
# # f = [x + y for x in "ASCD" for y in "2345"]
print(f)

列表生成器

相比生成式来说占用内存少

import sys
f = (x ** 2 for x in range(10))
print(sys.getsizeof(f))
print(f)
for v in f:
print(sys.getsizeof(f))# 输出占用的内存
print(v)

字典

字典的一切操作都是通过键名来进行,在这中间自然调动了键值

字典是无序的,没有索引操作,除非转换从有序字典

dict_ = {1:100,2:200}# 键名不可以一样,键值可以一样
# print(dict_.get(1))# 都是通过键名获得键值,使用get的好处当键名不存在时可以输出none,适用于字典动态变化的时候,可以遍历默认遍历出键名,
print(dict_[1])
print(dict_[2])

更新键值对

dict_ = {1:100,2:200}# 键名不可以一样,键值可以一样
# print(dict_.get(1))# 都是通过键名获得键值,使用get的好处当键名不存在时可以输出none,适用于字典动态变化的时候,可以遍历默认遍历出键名,
print(dict_[1])
print(dict_[2])
dict_.update(aaa=444)
print(dict_)
dict_.update([(3,300)])# 试了好多次,只找到这一种“传一个包含一个或多个元组的列表”的形式进行添加以数字为键名的键值对
print(dict_)
dict_.update([(3,300)])# 当重复添加一个相同的键名而键值一样是,字典元素不做任何改变
print(dict_)
dict_.update([(3,400),(3,500)])# 当重复添加一个相同的键名而键值不一样时,按照最后一个进行更新
print(dict_)

获取键值对

dict_ = {1:100,2:200}
for key,value in dict_.items():
print(key,value) # 获取键值对

      替换键值对、弹出键值对

dict_ = {1:100,2:200}
# dict_[1] = 10000 # 替换键值
# print(dict_)
print(dict_.pop(1))# 弹出并输出指定键名的键值,弹出后字典中不再有该键值对
print(dict_.popitem())# 弹出并输出最后一个键值对,弹出后字典中不再有该键值对
print(dict_)
清空字典
dict_ = {1:100,2:200}
dict_.clear()# 清空字典
print(dict_)

元组

  元组和数组的转换

a = (1,2,3)#这是个元组,元组不可被‘直接’修改,如果不需要进行增删改操作时最好用元组节省内存
a = [1,2,3]
# b = tuple(a)#定义一个数组
# print(b)#将数组转换为元组
print(a)

集合

a = {1,2,3}
# a = {1,2,3,1}#集合自动去重复,做某些去重可转化为集合再转换回去
print(a)

断更声明。由于时间及环境的变化限制,暂时无法继续学习python将会在未来进行重新更新。

Study python_04的更多相关文章

  1. Improve Your Study Habits

    1.Plan your time carefully. Make a list of your weekly tasks.Then make a schedule or chart of your t ...

  2. RSA Study

    These days I study the RSA Algorithm. It is a little complex, but not very. Also, my study has not f ...

  3. Machine Learning Algorithms Study Notes(3)--Learning Theory

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  4. Machine Learning Algorithms Study Notes(2)--Supervised Learning

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  5. Machine Learning Algorithms Study Notes(1)--Introduction

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1    Introduction    1 1.1    ...

  6. jar tvf study.war jar命令查看war/jar包的内容

    jar tvf study.war 0 Thu Oct 20 14:01:18 CST 2016 META-INF/ 137 Thu Oct 20 14:01:16 CST 2016 META-INF ...

  7. Mongo DB Study: first face with mongo DB

    Mongo DB Study: first face with mongo DB 1.  study methods: 1.  Translate: I am the mongo DB organiz ...

  8. A Study of WebRTC Security

    转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...

  9. study topics

    永远不变的东西,原理 study roadmap: 1.user space: tizen power manager => suspend/resume or runtime? android ...

  10. 读书笔记2013第10本:《学得少却考得好Learn More Study Less》

    <学得少却考得好Learn More Study Less>这本书最早是从褪墨网站上看到的,crowncheng翻译了全文.这本书介绍了不少学习方法,非常适合在校的学生,原文的作者Scot ...

随机推荐

  1. gulp安装出错

    gulp安装出错 标签(空格分隔): gulp 贴上报错: [root@localhost web]# npm install gulp --save-dev gulptest@1.0.0 /mnt/ ...

  2. SpringBoot打成war包,部署到Tomcat服务器

    SpringBoot默认达成jar包,使用SpringBoot构想web应用,默认使用内置的Tomcat.但考虑到项目需要集群部署或者进行优化时,就需要打成war包部署到外部的Tomcat服务器中.  ...

  3. Spyder无法使用搜狗输入中文的解决办法

    Ubuntu 18.04 LTS系统下,spyder4编辑器无法使用搜狗输入中文.系统输入法为fcitx+搜狗拼音,chrome浏览器无此问题.网上答案: Spyder (以及其他PyQt程序) 无法 ...

  4. elastalert部署和使用

    一.Elastalert简介 Elastalert是Yelp公司基于python开发的ELK日志告警插件,Elastalert通过查询Elasticsearch中的记录与定于的告警规则进行对比,判断是 ...

  5. 视频直播源码,js实现节流和防抖

    视频直播源码,js实现节流和防抖 防抖: 就是指连续触发事件但是在设定的一段时间内中只执行最后后一次,例如:设定1000毫秒执行,当你触发事件了,他会1000毫秒后执行,但是在还剩500毫秒的时候你又 ...

  6. python_test_0001_base_string

    #!/usr/bin/python # -*- coding: UTF-8 -*- from lib_001_decorator_log_funcname import decorator_log_f ...

  7. 【Java学习day04】Java文件的创建和Java代码的执行

    Java文件的创建和Java代码的执行 随便新建一个文件夹,存放代码 在新建的文件夹里新建一个java文件 新建一个文本文档 将新建的文本文档重命名为hello.java 注意了!后缀必须改为.jav ...

  8. 【Asp.net】服务器控件<asp:TextBox ></TextBox>如何变为多文本控件

    废话不多说,直接上图! 在TextBox上增加TextModel="MultiLine"即可!

  9. wake on lan magic packet

    局域网模式,必须电脑和手机在同一个 局域网,或者是网段内 外网模式  这个就是,你拿着手机,在任何地方,都可以开机电脑.

  10. 【Quartus系列】实验一: 3-8译码器(原理图输⼊设计)

    实验一: 3-8译码器(原理图输⼊设计) ⼀:实验⽬的 1. 了解3-8译码器的电路原理,掌握组合逻辑电路的设计⽅法 2. 掌握QuartusII软件原理图输⼊设计的流程 ⼆:实验内容 2.1设计输⼊ ...