File tree 2 files changed +60
-0
lines changed
2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Initialize it
2
+ test_list = [1 , 2 , 3 ]
3
+
4
+ # Append 4
5
+ test_list .append (4 )
6
+ # Insert 0 at 0th position
7
+ test_list .insert (0 , 0 )
8
+
9
+ print ("Test list: {}\n " .format (test_list ))
10
+
11
+ # Initialize it using its class name
12
+ next_list = list ()
13
+ next_list .append (7 )
14
+ next_list .append (2 )
15
+ next_list .append (5 )
16
+ next_list .append (1 )
17
+
18
+ print ("Next list: {}" .format (next_list ))
19
+ print ("Sorted next list (does not mutate): {}\n " .format (sorted (next_list )))
20
+
21
+ print ("So here's next_list: {}" .format (next_list ))
22
+ if 3 in next_list :
23
+ print ("3 is here!" )
24
+ else :
25
+ print ("No 3 :(" )
26
+
27
+ if 2 in next_list :
28
+ print ("2 is here!" )
29
+ else :
30
+ print ("No 2 :(" )
31
+
Original file line number Diff line number Diff line change
1
+ # Can define the list to loop through here
2
+ for x in [1 , 5 , 9 , 2 ]:
3
+ print ("I have a {}" .format (x ))
4
+
5
+ # Or loop through an existing object
6
+ cool_stuff = [3 , 7 , 21 , 18 ]
7
+
8
+ for num in cool_stuff :
9
+ print ("This {} is cool stuff" .format (num ))
10
+
11
+ # Range is a generator object -- we'll go over that later
12
+ for x in range (6 ):
13
+ print ("{} " .format (x ), end = '' )
14
+
15
+ # Just print a new line
16
+ print ()
17
+
18
+ go = True
19
+ while go :
20
+ if input ("Now type 'c' to continue: " ) == "c" :
21
+ # Note that even when the condition becomes false, the loop code will continue
22
+ go = False
23
+ print ("Still going!" )
24
+
25
+ while True :
26
+ # We'll leave if the user types q
27
+ if input ("Now type 'q' to quit: " ) == "q" :
28
+ break
29
+ print ("Not done yet!" )
You can’t perform that action at this time.
0 commit comments