

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


x = 10 # int y = 3.14 # float name = 'Alice' # str flag = True # bool nums = [1,2,3] # list
score = 75 if score >= 90: grade = 'A' elif score >= 70: grade = 'B' else: grade = 'C' print(grade) # B
count < 3: print(count) count += 1
def greet(name, greeting='Hello'): '''Return a personalised greeting string.''' return f'{greeting}, {name}!' print(greet('Bob')) # Hello, Bob! print(greet('Alice', 'Hi')) # Hi, Alice!
Structure Ordered Mutable Duplicates Example List Yes Yes Yes [1, 2, 3] Tuple Yes No Yes (1, 2, 3) Set No Yes No {1, 2, 3} Dictionary Yes* Yes Keys: No {'a': 1}
Reading from a file with open('data.txt', 'r') as f: content = f.read() print(content)
try: result = 10 / 0 except ZeroDivisionError as e: print(f'Error: {e}') finally: print('Always runs')