


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!



Print something: print("Hello, World!")
Variables: x = 5 name = "Alice"
Data Types:
Input from user: name = input("Enter your name: ")
if x > 0: print("Positive") elif x == 0: print("Zero") else: print("Negative")
For loop: for i in range(5): print(i)
While loop: while x > 0:
print(x) x -= 1
def greet(name): return f"Hello, {name}!"
print(greet("Alice"))
fruits = ["apple", "banana", "cherry"] fruits.append("orange") print(fruits[0]) # first item
Loop through list: for fruit in fruits: print(fruit)
person = {"name": "Alice", "age": 25} print(person["name"])
Add new key-value: person["city"] = "New York"
import math print(math.sqrt(16))