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 }}
CyberCoderWill
mycode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
mycode
/
python
/
python_sequence
/
tuple.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
75 lines (54 loc) · 1.36 KB
master
Breadcrumbs
mycode
/
python
/
python_sequence
/
tuple.py
Copy path
Top
File metadata and controls
Code
Blame
75 lines (54 loc) · 1.36 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
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
元组
元组是一种不可变的类型
默认集合类型
所有的多对象的,逗号分隔的,没有明确用符号定义的,这些集合默认的类型都是元组
"""
# 创建元组
aTuple = (123, 'abc', 4.56, ['inner', 'tuple'], 7 - 9j)
anotherTuple = (None, 'something to see here')
# 只有一个元素的元组需要在后面加上逗号
emptiestPossibleTuple = (None,)
tupleUseFun = tuple('bar')
print(aTuple)
print(anotherTuple)
print(emptiestPossibleTuple)
print(tupleUseFun)
# 访问元组的值
aTuple[1:4]
aTuple[:3]
aTuple[3][1]
# 如何更新元组,不能更新 或者改变元组的元住宿,需要新建元组
tup1 = (12, 34.56)
tup2 = ('abc', 'xyz')
print(tup1 + tup2)
# 删除元组的元素或者元组本身,bune不能删除一个单独的元组元素
del aTuple
# 元组操作符和内建函数
# 重复
t = (['xyz', 123], 23, -103.4)
print(t * 2)
# 连接
print(t + ('free', 'easy'))
# 成员关系操作,切片操作
print(23 in t)
print(t[0][1])
print(t[1:])
# 内建函数
print(str(t))
print(max(t))
print(min(t))
print(cmp(t, ()))
print(list(t))
# 操作符
print((2, 3) == (2, 3))
# 所有函数返回的多对象(不包括有符号封装的)都是元组类型
def foo1():
return 1, 2, 3
def foo2():
return [1, 2, 3]
def foo3():
return (1, 2, 3)
print(type(foo1()))
You can’t perform that action at this time.