Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91899 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2015-06-02 14:33 -0700 |
| Last post | 2015-06-02 21:49 +0000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
What is the difference between list() and list? fl <rxjwg98@gmail.com> - 2015-06-02 14:33 -0700
Re: What is the difference between list() and list? Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-02 17:38 -0400
Re: What is the difference between list() and list? "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-02 14:40 -0700
Re: What is the difference between list() and list? John Gordon <gordon@panix.com> - 2015-06-02 21:49 +0000
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2015-06-02 14:33 -0700 |
| Subject | What is the difference between list() and list? |
| Message-ID | <3ada3275-68c9-421c-aa19-53c312c42b1f@googlegroups.com> |
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? Thanks,
[toc] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2015-06-02 17:38 -0400 |
| Message-ID | <mailman.82.1433281108.13271.python-list@python.org> |
| In reply to | #91899 |
On Tue, Jun 2, 2015 at 5:33 PM, fl <rxjwg98@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
[toc] | [prev] | [next] | [standalone]
| From | "Dr. Bigcock" <dreamingforward@gmail.com> |
|---|---|
| Date | 2015-06-02 14:40 -0700 |
| Message-ID | <7429fbe6-d246-4712-b01f-5b8c1173ad67@googlegroups.com> |
| In reply to | #91899 |
On Tuesday, June 2, 2015 at 4:33:13 PM UTC-5, fl wrote: > I find the following results are interesting, but I don't know the difference > between list() and list. Interestingly, we've just been talking about this on another thread. list is like a class definition, a "type". Adding the parens () around it, invokes it or calls it, resulting in the instantiation of the "object". The difference between the two is that one is the blueprint of a building made by an architect (generally not something to modify) and the other is the building itself. You can modify the building after it's been specified, but the blueprint retains the intentions of the architect. --m
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2015-06-02 21:49 +0000 |
| Message-ID | <mkl8cv$dsi$2@reader1.panix.com> |
| In reply to | #91899 |
In <3ada3275-68c9-421c-aa19-53c312c42b1f@googlegroups.com> fl <rxjwg98@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
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web