Introduction to Python Programming
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and versatility. It
is widely used in web development, data science, artificial intelligence, and more.
Example:
print("Hello, Python!")
Sample Output:
Hello, Python!
Using IDLE to Develop Programs
IDLE is Python’s Integrated Development and Learning Environment. It allows you to write, run, and
debug Python programs interactively.
Basic Coding Skills
Python uses indentation for defining code blocks. Comments start with #. Variables are dynamically
typed.
Example:
# Single-line comment
x = 5
if x > 0:
print("Positive number")
Sample Output:
Positive number
2. Data Types and Variables - Numeric Data
Python supports integers, floats, and complex numbers. Arithmetic operations include +, -, *, /, %,
//, and **.
Example:
a = 10
b = 3
print(a + b)
print(a / b)
print(a ** b)
Sample Output:
13
3.3333333333333335
1000
String Data
Strings are sequences of characters. You can use single, double, or triple quotes. Common
operations include concatenation, slicing, and formatting.
Example:
name = "Python"
print(name[0])
print(name[1:4])
print(name.upper())
Sample Output:
P
yt
PYTHON
3. Python Functions
Functions are defined using the def keyword. They help organize code into reusable blocks.
Example:
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
Sample Output:
Hello, Alice!
4. Code Control Statements
Python supports if-else for conditional execution and for/while loops for iteration. break, continue,
and pass alter loop behavior.
Example:
for i in range(5):
if i == 2:
continue
print(i)
Sample Output:
0
1
3
4
5. Functions and Modules
Modules are Python files containing functions and variables. You can import standard modules or
create your own.
Example:
import math
print(math.sqrt(16))
Sample Output:
4.0
6. Lists and Tuples
Lists are mutable sequences, while tuples are immutable. Both can store multiple data types.
Example:
fruits = ["apple", "banana", "cherry"]
print(fruits[0])
fruits.append("date")
print(fruits)
colors = ("red", "green", "blue")
print(colors[1])
Sample Output:
apple
["apple", "banana", "cherry", "date"]
green