function returning a list

B

beliavsky

Brad Tilley said:
Can a function return a list?

Yes, it can return anything. Here is a trivial example:

def twice(x):
return 2*x

print twice(1.0) # 2.0
print twice([1.0]) # [1.0, 1.0]

Note that "2*x" has a very different effect, depending on what "x" is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,205
Messages
2,571,067
Members
47,673
Latest member
MahaliaPal

Latest Threads

Top