-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonTuple2.py
97 lines (83 loc) · 2.54 KB
/
PythonTuple2.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> #Python tuple 2 Day 17
>>> newtuple = ("apple", "banana","cherry")
>>> if "orange" in newtuple:
print("Yes")
>>> newtuple.clear()
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
newtuple.clear()
AttributeError: 'tuple' object has no attribute 'clear'
>>> del newtuple
>>> fruiTuple = ("apple", "banana","cherry")
>>> if "apple" in fruiTuple:
print("Yes")
Yes
>>> newtuple = ('Hi',) *3
>>> print(newtuple)
('Hi', 'Hi', 'Hi')
>>> temtuple = ('hello') * 2
>>> print(temtuple)
hellohello
>>> intTuple = (5) * 5
>>> print(intTuple)
25
>>> del intTuple
>>> intTuple = (5,) * 5
>>> print(intTuple)
SyntaxError: unexpected indent
>>> print(intTuple)
(5, 5, 5, 5, 5)
>>> intTuple += (1,2,3)
>>> print(intTuple)
(5, 5, 5, 5, 5, 1, 2, 3)
>>> print(len(intTuple))
8
>>> numTuple ((1,3), (3,4), (4,2), (1,4))
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
numTuple ((1,3), (3,4), (4,2), (1,4))
NameError: name 'numTuple' is not defined
>>> mergeTuple = tuple(("apple","banana", "cherry"))
>>> print(mergeTuple)
('apple', 'banana', 'cherry')
>>> mergeTuple = tuple(intTuple)
>>> print(mergeTuple)
(5, 5, 5, 5, 5, 1, 2, 3)
>>> thislist = [3,4,5,6, "A","B"]
>>> thisTuple = tuple(thislist)
>>> print(thisTuple)
(3, 4, 5, 6, 'A', 'B')
>>> print(thisTuple.count())
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
print(thisTuple.count())
TypeError: count() takes exactly one argument (0 given)
>>> print(intTuple.count(5))
5
>>> print(fruiTuple.index("banana"))
1
>>> if "cherry" in fruiTuple:
print("Yes in index" + fruiTuple.index('cherry'))
Traceback (most recent call last):
File "<pyshell#37>", line 2, in <module>
print("Yes in index" + fruiTuple.index('cherry'))
TypeError: can only concatenate str (not "int") to str
>>> if "cherry" in fruiTuple:
print("Yes in index" + str(fruiTuple.index('cherry')))
Yes in index2
>>> if "apple" in fruiTuple:
print("Yes in index " + fruiTuple.index('apple'))
Traceback (most recent call last):
File "<pyshell#41>", line 2, in <module>
print("Yes in index " + fruiTuple.index('apple'))
TypeError: can only concatenate str (not "int") to str
>>> if "apple" in fruiTuple:
print("Yes in index " + str(fruiTuple.index('apple')))
SyntaxError: unexpected indent
>>> if "apple" in fruiTuple:
print("Yes in index " +str(fruiTuple.index("apple")))
Yes in index 0
>>>