Concept Flow - List creation and representation
Start
Create empty list or with elements
Store list in variable
Print or use list
End
This flow shows how a list is created, stored in a variable, and then printed or used.
Jump into concepts and practice - no test required
my_list = [10, 20, 30] print(my_list)
| Step | Action | Variable | Value | Output |
|---|---|---|---|---|
| 1 | Create list with elements | my_list | [10, 20, 30] | |
| 2 | Print list | my_list | [10, 20, 30] | [10, 20, 30] |
| 3 | End of program |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| my_list | undefined | [10, 20, 30] | [10, 20, 30] | [10, 20, 30] |
List creation syntax: my_list = [item1, item2, ...] Lists hold ordered items inside square brackets. Elements are separated by commas. Printing a list shows its contents with brackets and commas. Lists can be empty: my_list = [] Lists are stored in variables for later use.
[] or the list() function.[] is the literal syntax for an empty list, while list() also creates an empty list but is a function call.[] to hold items in order.list = [1, 2, 3] uses square brackets with items 1, 2, 3 correctly. list = (1, 2, 3) uses parentheses which create tuples. list = {1, 2, 3} uses curly braces which create sets. list = <1, 2, 3> uses invalid syntax.my_list = [10, 'apple', 3.5] print(my_list)
my_list contains an integer, a string, and a float. Lists can hold mixed types.numbers = [1, 2, 3 print(numbers)
[ but does not have a closing ] bracket.x % 2 == 0.evens = [x for x in range(1, 6) if x % 2 == 0] correctly uses range 1 to 5 and selects even numbers. Other options select odd numbers or wrong ranges.