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 }}
stwhh
python3_basicstudy
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
python3_basicstudy
/
1.datastructure_list.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
65 lines (56 loc) · 1.53 KB
master
Breadcrumbs
python3_basicstudy
/
1.datastructure_list.py
Copy path
Top
File metadata and controls
Code
Blame
65 lines (56 loc) · 1.53 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#-*-coding:utf-8-*-
# # 1.列表 []标识
# 列表是有序的
# list=['a','b',2,'你好']
# print('开始列表:')
# for i in list:
# print('\t'+str(i))
#
# # 添加
# list.append('我是追加的')
# list.insert(1,'我是插入的,第二个')
# print('添加后的列表:')
# for i in list:
# print('\t'+str(i))
#
# # 修改
# list[0]='修改A'
# print('修改的列表:')
# for i in list:
# print('\t'+str(i))
#
# # 删除
# # 删除指定索引
# del list[0]
# print('del 删除的列表1:')
# for i in list:
# print('\t'+str(i))
#
# # 删除最后一个,并返回最后一个
# last = list.pop() # 可以带索引,删除指定索引的值并弹出这个值,比如pop(0),就是删除第一个元素并弹出
# print('del 删除的列表2:')
# for i in list:
# print('\t'+str(i))
# print(last)
#
# # 根据值删除(如果出现多次,只删除第一个,需要循环才能都删除)
# list.remove(2) # 可删除指定值
# list.remove('b') # 删除指定值
# print('remove 删除的列表:')
# for i in list:
# print('\t'+str(i))
# 列表解析
# 语法 [expression for iter_val in iterable if cond_expr]
squares =[item**2 for item in range(1,11)]
print(squares)
print(sum(squares))
for i in squares:
print(i)
# squares =[item**2 for item in range(1,11) if item%2==0]
# print(squares)
# print(sum(squares))
# 切片
players = ['charles', 'martina', 'michael', 'florence', 'eli']
print(players[:4]) # 从0,开始到第三个结束
print(players[-1:]) # 最后1名
print(players[-3:]) # 最后3名
You can’t perform that action at this time.