Full Python Syllabus QA Notes
Full Python Syllabus QA Notes
Example:
if x > 0:
print("Positive")
Example:
if x > 0:
print("Positive")
else:
print("Not Positive")
Example:
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
Example:
if x >= 0:
if x == 0:
print("Zero")
Example:
i=1
while i <= 5:
print(i)
i += 1
Example:
for i in range(5):
print(i)
Example:
for i in range(5):
if i == 3:
break
Example:
for i in range(5):
if i == 2:
continue
What is a nested loop?
Example:
for i in range(2):
for j in range(2):
print(i, j)
Unit 2: Strings and Functions
What is a function?
Example:
def greet():
print("Hi")
return a + b
Unit 3: Lists, Tuples, Sets, Dictionaries
What is a list?
What is a tuple?
What is a set?
What is a dictionary?
What is a class?
Example:
class Dog:
self.name = name
What is an object?
'self' refers to the instance. Attributes are variables inside the class.
Functions defined inside a class. They usually take self as first argument.
What is inheritance?
Example:
class Animal:
class Dog(Animal):