Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
fungitive
python-example
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
python-example
/
listcaozuo
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
36 lines (34 loc) · 1.91 KB
master
Breadcrumbs
python-example
/
listcaozuo
Copy path
Top
File metadata and controls
Code
Blame
36 lines (34 loc) · 1.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#列表对象方法
list.append(x)
#把一个元素添加到列表的结尾,相当于 a[len(a):] = [x]。
list.extend(L)
#将一个给定列表中的所有元素都添加到另一个列表中,相当于 a[len(a):] = L。
list.insert(i, x)
#在指定位置插入一个元素。第一个参数是准备插入到其前面的那个元素的索引,
#例如 a.insert(0, x) 会插入到整个列表之前,而 a.insert(len(a), x) 相当于 a.append(x)。
list.remove(x)
#删除列表中值为 x 的第一个元素。如果没有这样的元素,就会返回一个错误。
list.pop([i])
#从列表的指定位置删除元素,并将其返回。如果没有指定索引,a.pop() 返回最后一个元素。
#元素随即从列表中被删除(方法中 i 两边的方括号表示这个参数是可选的,而不是要求你输入
#一对方括号,你会经常在Python 库参考手册中遇到这样的标记)。
list.clear()
#从列表中删除所有元素。相当于 del a[:]。
list.index(x)
#返回列表中第一个值为 x 的元素的索引。如果没有匹配的元素就会返回一个错误。
list.count(x)
#返回 x 在列表中出现的次数。
list.sort()
#对列表中的元素就地进行排序。
list.reverse()
#就地倒排列表中的元素。
list.copy()
#返回列表的一个浅拷贝。等同于 a[:]。
创建tuple和创建list唯一不同之处是用( )替代了[ ]。
tuple没有 append()方法,也没有insert()和pop()方法。
获取 tuple 元素的方式和 list 是一模一样的,但是不能赋值成别的元素。
list 和 tuple 可以用来表示顺序集合。dict实现查找,
dict的第一个特点是查找速度快,无论dict有10个元素还是10万个元素,查找速度都一样。
dict的第二个特点就是存储的key-value序对是没有顺序的。
dict的第三个特点是作为 key 的元素必须不可变。
遍历dict和遍历list类似,都可以通过 for 循环实现。
You can’t perform that action at this time.