What does the list() function do in Python?

前端 未结 6 1592
暖寄归人
暖寄归人 2020-12-19 11:14

I know that the list() constructor creates a new list but what exactly are its characteristics?

  1. What happens when you call list((1,2,3,4,

6条回答
  •  鱼传尺愫
    2020-12-19 12:12

    Python has a well-established documentation set for every release version, readable at https://docs.python.org/. The documentation for list() states that list() is merely a way of constructing a list object, of which these are the listed ways:

    • Using a pair of square brackets to denote the empty list: []
    • Using square brackets, separating items with commas: [a], [a, b, c]
    • Using a list comprehension: [x for x in iterable]
    • Using the type constructor: list() or list(iterable)

    The list() function accepts any iterable as its argument, and the return value is a list object.

    Further reading: https://docs.python.org/3.4/library/stdtypes.html#typesseq-list

提交回复
热议问题