October 30, 2018 at 11:03 pm
Comments posted to this topic are about the item More Nested Tuples
October 30, 2018 at 11:03 pm
Nice, easy question, thanks, Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
October 31, 2018 at 6:53 am
Misread the question and picked option 5 - Costumes[1][2][0:1]
Would that return both "Blue" and "Orange"?
I'm not a regular SQL Server user anymore and not familiar with tuples...
October 31, 2018 at 7:01 am
nice question
cheers
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
October 31, 2018 at 5:30 pm
Arno.Hubert.Janssen - Wednesday, October 31, 2018 6:53 AMMisread the question and picked option 5 - Costumes[1][2][0:1]
Would that return both "Blue" and "Orange"?
I'm not a regular SQL Server user anymore and not familiar with tuples...
Hi Arno,
today's Qotd is about accessing values of Tuples in Python.
print Costumes[1][2][0:1]; returns ('Blue',)
print Costumes[1][2][1:2]; returns ('Orange',)
print Costumes[1][2][0:2]; returns ('Blue', 'Orange')
print Costumes[0][1][0:6]; returns Batman
October 31, 2018 at 6:35 pm
I tried below example from w3schools.com and getting an error.
Example:
thistuple = ("apple", "banana", "cherry")
thistuple[1] = "blackcurrant"
# The values will remain the same:
print(thistuple)
Result:
>>> thistuple = ("apple", "banana", "cherry")
>>> thistuple[1] = "blackcurrant"
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
thistuple[1] = "blackcurrant"
TypeError: 'tuple' object does not support item assignment
>>>
Any Idea.
ThanksSaurabh.D
October 31, 2018 at 7:13 pm
Saurabh.D - Wednesday, October 31, 2018 6:35 PMI tried below example from w3schools.com and getting an error.Example:
thistuple = ("apple", "banana", "cherry")
thistuple[1] = "blackcurrant"
# The values will remain the same:
print(thistuple)Result:
>>> thistuple = ("apple", "banana", "cherry")
>>> thistuple[1] = "blackcurrant"
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
thistuple[1] = "blackcurrant"
TypeError: 'tuple' object does not support item assignment
>>>Any Idea.
Tuples are immutable which means you cannot update or change the values of tuple elements.
You are able to take portions of existing tuples to create new tuples as the following example demonstrates:
#!/usr/bin/python
thistuple = ("apple", "banana", "cherry");
print thistuple;
fruits = ("apricot", "strawberry", "pear");
print fruits;
all_tuples = thistuple + fruits;
print all_tuples;
Result
$python main.py
('apple', 'banana', 'cherry')
('apricot', 'strawberry', 'pear')
('apple', 'banana', 'cherry', 'apricot', 'strawberry', 'pear')
November 1, 2018 at 5:40 am
Thanks George for the clarification!!!
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply