Jun 14, 2024
a = 10, b = 20. Operations: +, -, *, /.name = "EMC", age = "Porter".*input(). Example: name = input(), age = input().print("My name is", name), print("My age is", age).if a > 10:
print("Greater than 10")
else:
print("10 or less")
True and False.and, or, not: To combine multiple conditions.if a > 10 and b < 20:
print("Condition met")
for i in range(5):
print(i)
i = 0
while i < 5:
print(i)
i += 1
def keyword to define a function.def add(a, b):
return a + b
return a + bdef print_name(name):
print("My name is", name)
a = [1, 2, 3, 4]append(), insert(), remove(), etc.a = {1, 2, 3}add(), remove(), etc.a = {"name": "EMC", "age": 25}items(), keys(), values()class keyword.class MyClass:
x = 5
p1 = MyClass()class MyClass:
def __init__(self, name):
self.name = name
def greet(self):
print("Hello,", self.name)
class Parent:
def display(self):
print("Parent class")
class Child(Parent):
pass
class A:
pass
class B:
pass
class C(A, B):
pass
class Parent:
def show(self):
print("Parent method")
class Child(Parent):
def show(self):
print("Child method")
try:
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
print(a / b)
except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")