Python Syntax Basics
Python Syntax Basics
1. Basic Structure
Example:
if x > 0:
print("Positive")
else:
print("Non-positive")
x = 10 # int
3. Operators
Arithmetic: +, -, *, /, //, %, **
Assignment: =, +=, -=
4. Control Flow
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
for i in range(5):
Python Syntax Basics
print(i)
print(count)
count += 1
5. Data Structures
6. Functions
def greet(name):
7. Importing Modules
import math
print(math.sqrt(16))
8. Comments
"""
This is a
multi-line comment
"""
class Dog:
self.name = name
def bark(self):
my_dog = Dog("Buddy")
my_dog.bark()