An asterisk in Python is actually the standard multiplication operator *. It displays the method of the __mul__object it worked on, and therefore can be overloaded to have custom values. This has nothing to do with ifor print.
(str unicode) /, , "foo" * 5 "foofoofoofoofoo".
>>> 'foo' * 5
'foofoofoofoofoo'
"Fizz" * (i % 3 == 0) "" :
"Fizz" if i % 3 == 0 else ""
, i % 3 == 0 , boolean - Python, True == 1 False == 0, , "" , ' , .
.. , / Python - ( , ), ( , , , . http://pastebin.com/Q92j8qga ( , PyPy: http://pastebin.com/sJtZ6uDm)).
* list tuple:
>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> (1, 2, 3) * 3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
* , Python:
class Foo(object):
def __mul__(self, other):
return "called %r with %r" % (self, other)
print Foo() * "hello"
:
called <__main__.Foo object at 0x10426f090> with 'hello'
*, __mul__, "" , int, float , 3 * 4 (3).__mul__(4) ( ). int *:
class MyTrickyInt(int):
def __mul__(self, other):
return int.__mul__(self, other) - 1
def __add__(self, other):
return int.__add__(self, other) * -1
print MyTrickInt(3) * 4
print MyTrickyInt(3) + 2
... , , :) ( , !)