Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#PYTHON#9420 Back

List creation variations

Lists can be created by direct declaration of values that go into it using square brackets. Constructor based creation can also be used.

Source Code

		 

Click to open popup

Run Output

[10, 20, 30]
[10]
[10]
['A', 'B', 'C', 'D']
[1, 2, 3, 4, 5]
[10, 20, 30]

Notes

  • The constructor based creation takes any sequence (list, tuple or range) input and creates a list out of it. The same input can be given in a literal form or by way of taking the user input.
  • The original iterable is not changed when list is used to create a list from it.