print without ()
Glenn Hutchings
zondo42 at gmail.com
Thu Sep 7 02:26:12 EDT 2017
On Thursday, 7 September 2017 07:14:57 UTC+1, Andrej Viktorovich wrote:
> Sometimes I find code with strange print function usage. String is passed without brackets.
>
> #!/usr/bin/python
> list = ['physics', 'chemistry', 1997, 2000];
> print "Value available at index 2 : "
> print list[2]
> list[2] = 2001;
> print "New value available at index 2 : "
> print list[2]
>
> If I use command print "aaa" in console I get error. So, why this is allowed in sample?
>
> Sample from:
> https://www.tutorialspoint.com/python/python_lists.htm
That's because of a difference between python 2 and python 3. In python 3, print is a function (which requires brackets). In python 2 it was a keyword. The tutorial you're looking at is from python 2.
More information about the Python-list
mailing list