Skip to content

Commit

Permalink
元组
Browse files Browse the repository at this point in the history
  • Loading branch information
CanisMinor-1037 committed Jul 25, 2024
1 parent 0462a0c commit 806a8e0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ch02/tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tuple1 = 1, 2 + 3
print(type(tuple1))

tuple2 = ("the", 1, ("and", "only"))
print(tuple2)

print(type((10, 20)))

empty_tuple = ()
single_element_tuple = (10,)
print(type(empty_tuple))
print(type(single_element_tuple))

code = ('up', 'up', 'down', 'down') + ('left', 'right') * 2
print(code)
print(len(code))
print(code.count('up'))
print(code.index('right'))

list1 = [0, 1, 2]
has_mutable_element_tuple = (list1, 'up')
print(has_mutable_element_tuple)
has_mutable_element_tuple[0].reverse()
print(has_mutable_element_tuple)

a, b = 1, 2
print(a, b)

0 comments on commit 806a8e0

Please sign in to comment.