Re: What is the difference between list() and list?

2015-06-02 Thread John Gordon
In 3ada3275-68c9-421c-aa19-53c312c42...@googlegroups.com fl 
rxjw...@gmail.com writes:

 I find the following results are interesting, but I don't know the difference
 between list() and list.

'list()' invokes the list class, which creates and returns a new list.
Since you haven't passed any arguments, the list is empty.

'list' refers to the list class itself.

Here is a more in-depth example, using functions instead of classes:

def hello(name):
return 'Hello'.

If you call this function, like so:

greeting = hello()
print greeting

You will get the output 'Hello'.

But, if you just REFER to the function, instead of actually CALLING it:

greeting = hello
print greeting

You will get this output:

function hello at 0xbb266bc4

Because you omitted the double parentheses, you're getting the hello
function object itself, instead of the RESULT of that function.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the difference between list() and list?

2015-06-02 Thread Joel Goldstick
On Tue, Jun 2, 2015 at 5:33 PM, fl rxjw...@gmail.com wrote:
 Hi,

 I find the following results are interesting, but I don't know the difference
 between list() and list.






 nums=list()
 nums
 []
 xx=list
 xx
 type 'list'
 nums
 []
 print(xx)
 type 'list'
 print(nums)
 []




 Could you tell me that?

list is the name of a built-in function that returns a list object
when you set xx = list, you are giving that function a new name -- 'xx'
when you invoke the function:  xx() or list() it returns a list

 Thanks,
 --
 https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list