- Variables and Data Types
- Control Structures
- Functions
- Lists and Dictionaries
- File Handling
name = "John" # creates a variable 'name' with the value "John"
age = 25 # creates a variable 'age' with the value 25
height = 1.75 # creates a variable 'height' with the value 1.75
is_student = True # creates a variable 'is_student' with the value True
string = "Hello, World!" # creates a string variable
integer = 42 # creates an integer variable
float = 3.14 # creates a float variable
boolean = True # creates a boolean variable
if x > 0:
print("x is positive")
elif x == 0:
print("x is zero")
else:
print("x is negative")
for i in range(10):
print(i)
while x < 10:
print(x)
x += 1
def greet(name):
print("Hello, " + name + "!")
greet("John")
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # prints "apple"
print(fruits[-1]) # prints "cherry"
fruits.append("orange")
fruits.insert(1, "pear")
person = {"name": "John", "age": 25, "is_student": True}
print(person["name"]) # prints "John"
print(person.get("age")) # prints 25
person["height"] = 1.75
person.update({"weight": 70})
with open("file.txt", "r") as f:
contents = f.read()