This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = ('a', 'b', 'c') | |
print(aTuple.index('a')) | |
# 打印出 'a'索引值為 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = ('to', 'be', 'or', 'not', 'to', 'be') | |
print(a.count('to')) | |
# 打印出2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = ('Amy', 18, 'Tapei') | |
name,age,_ = aTuple | |
print(name) | |
print(age) | |
# 打印出 Amy | |
# 打印出 18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = ('Amy',18) | |
name,age = aTuple | |
print(name) | |
print(age) | |
# 打印出 Amy | |
# 打印出 18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = ('a','b','c','d','e') | |
print(aTuple[0:2]) | |
# 打印出 ('a', 'b') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = ('a','b','c') | |
print(aTuple[0]) | |
# 打印出 a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tuple1 = 12, # 這樣就定義了只有一個元素的元組 | |
Tuple2 = (12,) # 後面必須要再加一個逗號,否則就是一個普通的值 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aList = [1,2,3] | |
aTuple = tuple(aList) | |
print(aTuple) | |
# 打印出 (1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = (1,2,3) | |
print(aTuple) | |
# 打印出 (1,2,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aTuple = (1,2,3) | |
print(aTuple) | |
# 打印出 (1,2,3) |