Introduction to Python
What is Python?
Python is a high-level, general-purpose programming language — which basically means it's a language you can use to tell a computer what to do, but in a way that feels almost like writing English sentences rather than complex machine code.
When you write Python, the computer reads your instructions and executes them. You can use Python to build websites, automate tasks, analyze data, create AI systems, write games, and much more — all with the same language.
Why Learn Python?
There are hundreds of programming languages. Python has become the most popular one for very specific reasons — it's designed to be human-readable and versatile.
{} like other languages. This forces clean, readable code and makes it easy to understand even months later.Compare: Hello World in 3 languages
// Java (verbose, lots of boilerplate) public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } } // C++ (complex syntax) #include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; } # Python (simple, clean, readable) print("Hello, World!")
Python lets you do the same thing in 1 line instead of 5–8 lines. This is why beginners learn Python 3× faster than other languages — and why companies love it too (less code = fewer bugs).
Where Python is used in the real world
Companies that rely on Python
A Brief History of Python
Python didn't appear out of nowhere. Understanding its history helps you appreciate why it's designed the way it is.
import this and press Enter. You'll see "The Zen of Python" — 19 guiding principles for writing good Python code, written by Tim Peters. Try it after you install Python!Installing Python
Before writing code, you need Python installed on your computer. It takes about 5 minutes. Follow the steps for your operating system.
🪟 Windows Installation
cmd, press Enter). Type python --version and press Enter. You should see Python 3.12.x.🍎 Mac Installation
python3 --version → you should see the version number.🐧 Linux Installation
# Update package list sudo apt update # Install Python 3 sudo apt install python3 python3-pip # Verify installation python3 --version
💻 Setting Up VS Code (Recommended Editor)
A code editor makes writing Python much easier. We recommend Visual Studio Code — it's free, fast, and has amazing Python support.
Ctrl+Shift+P → Type "Python: Select Interpreter" → Choose Python 3.12.Your First Python Program
It's time to write actual code. Let's start with the most famous program in the world — "Hello, World!" — and then go a few steps further.
Method 1 — Run Python Interactively (REPL)
The Python REPL (Read-Evaluate-Print Loop) lets you type code and see results immediately — perfect for testing.
# Open terminal and type: python # Windows python3 # Mac / Linux # You'll see something like: Python 3.12.0 (main, Oct 3 2023) >>> # This is the REPL prompt. Type code here! >>> print("Hello, World!") Hello, World! >>> 2 + 3 5 >>> print("My name is Python!") My name is Python!
Method 2 — Write a Python File (.py)
For real programs, you write code in a file with the .py extension and run it from the terminal. This is how all real Python projects work.
# This is your first Python program! # Lines starting with # are comments — Python ignores them print("Hello, World!") print("Welcome to Python!") print("I am learning to code on BitWithBite.")
python hello.py (Windows) or python3 hello.py (Mac/Linux) and press Enter. You'll see the output printed below!Going Further — Your Name Program
Let's write a slightly more interesting program that asks for your name and greets you personally.
# greeting.py # An interactive greeting program print("=============================") print(" Welcome to Python! 🐍") print("=============================") name = input("What is your name? ") print(f"Hello, {name}! Great to meet you!") print(f"Welcome to Python, {name}. Let's build something amazing!")
Don't worry if you don't understand every part yet — you'll learn input() in Module 5 and f-strings in Module 3. For now, just focus on running the code and seeing the output. That's the most important thing at this stage.
print() is a built-in Python function that displays text on the screen. Whatever you put inside the parentheses (in quotes) gets printed. This is the most used function in all of Python — you'll use it thousands of times.Python 2 vs Python 3
You might encounter old tutorials or books that use Python 2. Here's what you need to know about the differences:
# Python 2 (OLD — do NOT use) print "Hello" # print is a statement 5 / 2 # gives 2 # integer division by default unicode("hello") # separate unicode type # Python 3 (CURRENT — always use this) print("Hello") # print is a function 5 / 2 # gives 2.5 # true division by default "hello" # all strings are unicode
The rule is simple: always use Python 3. Python 2 reached end-of-life in January 2020 and no longer receives security updates. Every lesson in this course uses Python 3.
The Zen of Python
Python has a philosophy — a set of guiding principles that explain why Python looks and works the way it does. You can read it by running import this in Python. Here are the most important ones for beginners:
Simple is better than complex. Don't overcomplicate solutions.
Readability counts. Code is read more often than it is written.
Errors should never pass silently. Always handle errors explicitly.
There should be one obvious way to do it. Python prefers one clear solution.
Lesson Summary
Let's recap everything you learned in this lesson:
python --version.print() is the most basic Python function — it displays text on the screen..py file and run it from terminal.# are comments — Python ignores them. Use them to explain your code.print() function do in Python?Now it's your turn to write real code. Complete the challenge below in VS Code or any Python environment.
Write a Python program called
mycard.py that prints a nicely formatted "ID Card" about yourself. Your output should look like this (with your own details):
MY PYTHON ID CARD 🐍
================================
Name : Ahmed Khan
Country : Pakistan
Language : Python 3
Goal : Become an AI Engineer
Platform : BitWithBite.com
================================
Hello World! My Python journey starts TODAY!
================================
Rules: Use only
print() statements. Add at least one comment at the top of your file. Use your real name and goal.
💡 Show hints if you're stuck
- Use
print("text here")for each line - For the separator line, use
print("=" * 32)— Python repeats the character 32 times - Start your file with a comment:
# My Python ID Card Program - Run the file with
python mycard.pyin terminal