import sys
sys.version
'3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:22) [Clang 13.0.1 ]'
import sys
sys.version
'3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:22) [Clang 13.0.1 ]'
if
- elif
- else
= 4 a
Conditionals do not require parentheses:
if a < 10:
print("hello")
hello
But they work with them just the same:
if (a < 10):
print("hey")
hey
= 9 x1
if x1 > 10:
print("x1 is greater than 10")
elif 5 < x1 <= 10:
print("x1 is between 5 and 10")
else:
print("x1 is not very big")
x1 is between 5 and 10
for
loopsfor i in range(4):
print("Working on Feature " + str(i))
Working on Feature 0
Working on Feature 1
Working on Feature 2
Working on Feature 3
enumerate()
enumerate(iterable, start=0)
outputs pairs of an index (starting at start
) and an item from iterable
= ['one', 'two', 'three', 'four'] a
for it in enumerate(a):
print(it)
(0, 'one')
(1, 'two')
(2, 'three')
(3, 'four')
for i, el in enumerate(a, start=1):
print("Item number ", i, ": ", el, sep = '')
Item number 1: one
Item number 2: two
Item number 3: three
Item number 4: four
while
loops= 18
x while x > 12:
-= 1
x print(x)
17
16
15
14
13
12