Python Basics 1
Python Basics 1
PYTHON BASICS
Python is designed to be easy to read and write, with a syntax
that emphasizes clarity. This readability makes it an excellent
choice for beginners, while its powerful libraries and
frameworks attract seasoned developers.
CONTROL STRUCTURES
Control structures in Python allow for conditional execution and
repeated execution of code blocks. The primary control structures are:
python
if x > y:
print("x is greater than y")
elif x == y:
print("x is equal to y")
else:
print("x is less than y")
for i in range(5):
print(i) # Prints numbers from 0 to 4
count = 0
while count < 5:
print(count)
count += 1
FUNCTIONS AND MODULES
Functions
Functions in Python are defined using the def
keyword. They encapsulate reusable code blocks
that can be called with arguments and can
return values.
def greet(name):
return f"Hello, {name}!"