You are already aware of list() used in python. We use it to create a list either an empty one or from other iterables such as tuple, set, etc.
Consider the following :
list1=list()
t=(1,2,3)
list2=list(t)
My major doubt here is, the name 'list' is a separate function named list or name of the class 'list'?
The reason for my doubt is, the syntax for creating an object is :
obj_name=class_name()
We have created the objects list1 and list2 as given in the syntax
Also
help(list)
Output :
Help on class list in module builtins:
class list(object)
.....
.....
.....
__hash__=None
Gives the information only about the class list. Whereas for other built-in functions such as len(), the help() gives the functions' information
help(len)
Output :
Help on built-in function in module builtins:
len(obj, /)
Return the number of items in a container.
Hence, Is list() used as class name here to define its object???
Or is there a separate function to create a variable of type 'list' named list()???
To be more specific in my question, in the above code, Does list() acts as a class name or a function name?
If it is a built in function, can l get the code written for it???
Thanks in advance
from list() a function? Or class name?
No comments:
Post a Comment