Difference between revisions of "Python-lists"

From wikipost
Jump to navigationJump to search
Line 2: Line 2:
  
  
Python uses lists and sets (aka dictionaries)
+
The definition of lists in Python is
 +
 
 +
Python uses lists and literals
  
 
* Lists have square brackets
 
* Lists have square brackets
Line 12: Line 14:
 
</pre>
 
</pre>
  
* Sets have curly braces
+
* Literals have curly braces
  
 
<pre>
 
<pre>

Revision as of 15:31, 17 December 2020

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