Python-lists

From wikipost
Revision as of 15:31, 17 December 2020 by Admin (talk | contribs)
Jump to navigationJump to search

parsing lists in python


The definition of lists in Python is

Python uses lists and literals

  • Lists have square brackets
mylist = [1, 2, 3]
mylist = ['green', 'red', 'blue']
mylist = ['name', [43, 35, 14, 77], 'blue', 2018]
  • Literals have curly braces
myset = {'yellow', 'orange'}


just numbers

my_list = [28, 56, 45]

for item in my_list:
  print(item)

Output:

28
56
45


just words

my_list = ["green", "red", "blue"]

for item in my_list:
  print(item)

Output:

green
red
blue


2 dimensions