Python notes: List

yukiwu 2021-02-23 00:07:20
python notes list


Maybe like most ordinary people , I went through a special 2020 year . At sea , Getting sleepy , Straighten out self-cultivation .

finally 2021 In the spring of the recovery of all things , I stood myself up , Start learning and recording again . The first step is to organize or review systematically Python. I used to study intermittently because of my work , All the knowledge you know is scattered , Writing code is patchwork .

I hope this review can get a complete picture .

List

list Is the container data type (collection) One of them , It allows multiple values to be stored in a variable .

List Constants

list Can store any Python data type , for example number,string,character, Even list.

list = [] #empty list
list = [1, 2, 3, 4]
list = ['a', 'b', 'c', 'd']
list = ["apple", "banana", "cat", "dog"]
list = [1, [2, 3], 4]

And string similar ,list You can also use indexing obtain list A value in , Such as :

list = [1, 2, 3, 4]
print(list[2])
>> 3

But and string The difference is , list The value of is modifiable , and string The value of is not modifiable .

list = ['a', 'p', 'p', 'l', 'e']
list[2] = 'x'
print(list)
>> ['a', 'p', 'x', 'l', 'e']

List Manipulating

To connect or divide list, There are two important symbols , Namely “+” and “:”.

“+” It's used to connect two list, Such as :

a = [1, 2]
b = [3, 4]
list = a + b
print(list)
>> [1, 2, 3, 4]

“:” It's for segmentation list Of , Such as :

list = [1, 2, 3, 4, 5]
sublist = list[1:3] #from index = 1 to index = 3-1
print(sublist)
>> [2, 3]
sublist = list[:3] #from index = 0 to index = 3-1
print(sublist)
>> [1, 2, 3]
sublist = list[1:] #from index = 1 to index = len(list) -1
print(sublist)
>> [2, 3, 4, 5]

List Methods

List a few commonly used methods.

  • append: Add a new value
  • in: Check list Whether to include a value
list = [1, 2, 3, 4]
print(9 in list)
>> False
  • sort: Yes list Sort by
  • len: Calculation list The length of
  • max,min,sum: Calculation list The maximum of , Minimum and sum

List and Loop

If you need to traverse list Each value in is also simple , We can use for:

list = [1, 2, 3, 4, 5]
for ii in list:
print(ii)

You can also use for and range() Traverse list Medium index, To obtain list Value :

list = [1, 2, 3, 4, 5]
for ii in range(len(list)):
print(list[ii])
版权声明
本文为[yukiwu]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/02/20210222153751022B.html

  1. 使用Python开发DeFi项目
  2. python 函数详解
  3. Python工程师是做什么的?前景如何?
  4. Python - zip() 函数
  5. 30 周年生日,Python 先驱是怎么评价这门语言的?
  6. python将excel自适应导入数据库
  7. 从小白到大师,这里有一份Pandas入门指南
  8. [Python] 茎叶图和复合饼图的画法
  9. [Python interface automation] - regular use case parameterization
  10. Translation: practical Python Programming 02_ 02_ Containers
  11. Two years of Java, to write Python and go
  12. Translation: practical Python Programming 02_ 02_ Containers
  13. Two years of Java, to write Python and go
  14. Python-geoplot 空间核密度估计图绘制
  15. Python-seaborn 经济学人经典图表仿制
  16. python空间绘图- regionmask掩膜操作示例
  17. Python 空间绘图 - Cartopy 经纬度添加
  18. Python-pykrige包-克里金(Kriging)插值计算及可视化绘制
  19. Python 批量重采样、掩膜、坡度提取
  20. python - 多种交通方式可达圈分析
  21. Python 空间绘图 - 房价气泡图绘制
  22. Translation: practical Python Programming 02_ 02_ Containers
  23. Research on Portfolio Optimization Based on particle swarm optimization
  24. Ubuntu deploying Django project
  25. Two years of Java, write Python and go without byte beating
  26. Translation: practical Python Programming 02_ 02_ Containers
  27. So learn python, grandfather learned! Introduction to super simple Python
  28. python3 多线程 与 mongo亿级消费日志数据 新鲜demo 【优化第一版】
  29. Summary of Chinese word segmentation based on Jieba
  30. I've heard it n times, but I'm not impressed. After reading this, you'll understand
  31. Summary of Chinese word segmentation based on Jieba
  32. From movie art to Python code to realize God's reverse thinking mode
  33. Summary of Chinese word segmentation based on Jieba
  34. ARIMA模型预测CO2浓度时间序列-python实现
  35. Python belongs to back-end development or front-end development? Introduction to Python!
  36. python isinstance()
  37. I've heard it n times, but I'm not impressed. After reading this, you'll understand
  38. This article will familiarize you with the transformation process of Python - & gt; cafe - & gt; om model
  39. 如何用Python一键修改上万个文件名
  40. One day quick start to Python
  41. Python 学习笔记: List
  42. 翻译:《实用的Python编程》02_03_Formatting
  43. Is there any age requirement for learning Python? Is 30 OK?
  44. Professor Tsinghua! The most complete Python tutorial in 12 hours (free sharing at the end of the article)
  45. Using Python to develop defi project
  46. Detailed explanation of Python function
  47. Python 可变类型作为函数默认参数时的副作用
  48. What do Python engineers do? What's their future?
  49. 这是我见过最好的Python教程:十分钟带你认识Python
  50. Python欢喜冤家:爬虫与反爬虫带着处理方案来给大家拜年了
  51. Python - zip() function
  52. 写Python会遇到如下的错误:ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package
  53. Python类的调用以及私有和公有属性方法的调用
  54. Python类的专有方法
  55. Python基础之:数字字符串和列表
  56. How did Python pioneers evaluate this language on their 30th birthday?
  57. Python基础之:数字字符串和列表
  58. Python基础之:数字字符串和列表
  59. 窥探未来不是梦,python数据分析轻松实现
  60. This article will familiarize you with the transformation process of Python - & gt; cafe - & gt; om model