Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
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 }}
ItJava
Python24
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Python24
/
00Python
/
day05
/
basic01.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
42 lines (36 loc) · 1.32 KB
master
Breadcrumbs
Python24
/
00Python
/
day05
/
basic01.py
Copy path
Top
File metadata and controls
Code
Blame
42 lines (36 loc) · 1.32 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
37
38
39
40
41
42
"""
list列表元素的修改操作
"""
a_list
=
[
1
,
2
,
3
,
4
]
a_list
[
2
]
=
"双击666"
print
(
a_list
)
"""
查询list元素 (in, not in, index, count)
为了避免index方法找不到的报错,解决方案:
1, 先判断是否in,然后再list.index进行获取
2, 判断count非零即真,-1等负数也是真,再进行获取
"""
if
1
in
a_list
:
print
(
"存在"
)
if
88
not
in
a_list
:
print
(
"不存在list中"
)
print
(
a_list
.
index
(
2
))
# 查询某个元素的index, 找不到的话不返回-1,直接报错
print
(
a_list
.
count
(
2
))
# 查询某一个元素出现的次数
if
a_list
.
count
(
22
):
print
(
"22元素存在可以安全的获取索引:%d"
%
a_list
.
index
(
22
))
else
:
print
(
"元素不存在列表中"
)
"""
list删除元素
del 是一个内置函数,并不是属性, del 函数直接销毁对象
pop 是属性,pop()默认删除最后一个,pop(1)删除索引为1的元素,并且返回该元素
remove 是属性, pop是知道索引进行删除,remove是知道obj进行删除
clear 清空为[]
"""
b_list
=
[
1
,
2
,
3
,
4
]
del
b_list
[
2
]
# del b_list的话会直接删除b_list整个list,销毁对象,再print的话就话undefined
print
(
b_list
)
print
(
b_list
.
pop
(
0
))
b_list
.
remove
(
2
)
# remove不存在的元素会抛异常报错
b_list
.
clear
()
print
(
b_list
)
You can’t perform that action at this time.