Introduction To Python Programming
Python is a powerful, high-level programming language created by Guido van Rossum in 1991. It is an interpreted, object-oriented language renowned for its simplicity, readability, and versatility — making it the perfect choice for beginners and professionals alike in web development, data science, automation, machine learning, and beyond.
Why Python?
Readability
Python syntax resembles plain English, making it easier to learn, write, and maintain code.
Versatility
Used in web development, data science, automation, machine learning, AI, and game development.
Simplicity
Write fewer lines of code for the same functionality compared to languages like Java or C++.
Large Community
Extensive online support, libraries, frameworks, and active community help at every step.
Cross-Platform
Python runs on Windows, macOS, Linux, and other platforms without code changes.
Getting Started
- Installation: Download Python from the official website python.org/downloads.
- Python 3 vs Python 2: Always use Python 3 for new projects (Python 2 is deprecated).
- Choose an IDE: Use PyCharm, Visual Studio Code, Sublime Text, or even IDLE (bundled with Python).
- Benefits of IDEs: Code completion, syntax highlighting, debugging tools, and integrated terminal.
Writing Your First Python Program
# This is a comment
print("Hello, World!")
- Comments: Lines starting with
#are comments — ignored by Python. - print() function: Displays output to the console.
- No semicolons or braces: Python uses indentation to define code blocks.
Basic Input and Output
name = input("Enter your name: ")
print("Hello, " + name + "!")
Hello, John!
Python Data Types
| Type | Description | Example |
|---|---|---|
| int | Integer numbers | x = 5 |
| float | Decimal numbers | pi = 3.14 |
| str | Text/String | name = "Python" |
| bool | True or False | is_active = True |
| list | Ordered collection | nums = [1, 2, 3] |
| tuple | Immutable list | coords = (10, 20) |
| dict | Key-value pairs | user = {"name": "John"} |
Variables & Constants
- Variables: Named containers that store data during program execution.
- No declaration needed: Python automatically determines the data type.
- Naming rules: Start with a letter or underscore, use letters, numbers, and underscores.
- Constants: By convention, use UPPERCASE names for constants (e.g.,
PI = 3.14159).
age = 25 # Integer height = 5.9 # Float name = "Alice" # String is_student = True # Boolean
Operators
Control Flow
Conditional Statements
if, elif, and else execute code based on conditions.
For Loops
for loops iterate over sequences (lists, strings, ranges).
While Loops
while loops repeat as long as a condition is true.
age = 18
if age >= 18:
print("You are an adult")
else:
print("You are a minor")
for i in range(1, 6):
print(i)
2
3
4
5
Functions
- Built-in functions: Python provides many ready-to-use functions like
print(),len(),type(),sum(). - User-defined functions: Create your own reusable functions using the
defkeyword. - Parameters: Functions can accept inputs (arguments) and return outputs.
def greet(name):
return "Hello, " + name
message = greet("PBA Institute")
print(message)
More Examples
a = 10
b = 20
c = 30
total = a + b + c
print("Sum:", total)
PI = 3.14159
radius = 5
area = PI * radius ** 2
print("Area of circle:", area)
Next Steps
- Practice Daily: Write code every day — even small programs reinforce concepts.
- Build Projects: Create calculators, games, automation scripts, web scrapers.
- Explore Libraries: Learn NumPy, Pandas, Django, Flask, TensorFlow based on your interests.
- Join Communities: Participate in forums like Stack Overflow, Reddit, Discord.
- Read Documentation: Official Python docs at docs.python.org are excellent.
Conclusion
Python is one of the most beginner-friendly yet powerful programming languages in the world. Its clean syntax and versatility make it ideal for learning programming fundamentals while being robust enough for professional applications in AI, data science, web development, and automation. Start small, practice consistently, and build real projects — that's the key to mastering Python!