Reputation: 4498
I'm new to python. I have this sample program:
def main():
a = [4,2,1,6]
b = sorted(a)
for i in b:
print i
Where does sorted come from, or is this a python keyword of some sort? Same question with print i. This is python 2.7 by the way.
Upvotes: 1
Views: 109
Reputation: 12241
According to the documentation, it's a built in function.
Print is a statement in Python 2.7 - see the documentation here. Note that's no longer true in Python 3, where print is now a function.
Upvotes: 1
Reputation: 251538
sorted
is not a method but a Python builtin function. They are listed here: http://docs.python.org/2/library/functions.html
In Python 2, print
is a statement, which is one sort of keyword. In Python 3 it has been changed so that print
is a builtin function.
Upvotes: 7