In python how we need to print a same string many times without using loop.
I cane across something like * operator for this .
How we Can use this in a print statement ?
I am using python 3.x
Please help me
In python
print "ABCD" * 4
---------- Post updated at 03:01 PM ---------- Previous update was at 02:59 PM ----------
$ python -c "print \"ABCD\" * 4"
ABCDABCDABCDABCD
---------- Post updated at 03:04 PM ---------- Previous update was at 03:01 PM ----------
In Perl
$ perl -e 'print "ABCD" x 4'
ABCDABCDABCDABCD
Will that work in python 3.x?
I ll chk and let you know
i am using 2.6.4
so it will work in 3.x
Please find the result:
>>> print "ABCD" * 4
SyntaxError: invalid syntax
>>> print ("ABCD" * 4)
ABCDABCDABCDABCD
My version is :
>>> import sys
>>> sys.version
'3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]'
if you are inside the python console, they try the below
>>> 'abc' * 4
'abcabcabcabc'
Yes. its working.
>>> 'abc' * 4
'abcabcabcabc'
May i know is it possible to customize the ">>>" to "|||" in python console?
Thanks
i am not sure about that...
check here
2. Using the Python Interpreter � Python v2.7.2 documentation