Archive:Python/Operators: Difference between revisions

wikademia>ArrowStomper
wikademia>ArrowStomper
Line 127: Line 127:


'''TypeError: can only concatenate tuple (not "str") to tuple'''
'''TypeError: can only concatenate tuple (not "str") to tuple'''
====Multiplying ''Types''====
Multiplying is very easy and straight forward.
Type:
>>>'''x = 'dog''''
Now type:
>>>'''x * 5'''
''''dogdogdogdogdog''''
Now with a tuple.
Type:
>>>'''x = ('dog',)'''
Now Type:
>>>'''x * 5'''
'''('dog', 'dog', 'dog', 'dog', 'dog')'''
Now with a dictionary.
Type:
>>>'''x = {'dog':1}'''
Now Type:
>>>'''x * 5'''
'''Traceback (most recent call last):'''
'''File "<pyshell#5>", line 1, in ?'''
'''x * 5'''
'''TypeError: unsupported operand type(s) for *: 'dict' and 'int''''
You can't do it with dictionaries, that would make more than one of the same key, remember.


===Indexing===
===Indexing===