Introduction To Python
Introduction to Python: What is Python?
Python is a high-level, interpreted, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace.
1. Why Learn Python?
Python is one of the most popular programming languages in the world due to its:
- Simple Syntax: It reads almost like English, making it beginner-friendly.
- Versatility: Used in Data Science, Web Development, Automation, AI, and more.
- Large Community: Massive support and millions of libraries (like NumPy, Django, Pandas).
- Interpreted Language: Code is executed line by line, making debugging easier.
2. Your First Program: "Hello, World!"
In Python, writing your first program is incredibly simple. Unlike other languages that require headers or complex setup, Python only needs one line.
Writing the Code
Open your editor and type the following:
print("Hello, World!")
Running the Program
- Save the file as
hello.py. - Open your terminal or command prompt.
- Type
python hello.pyand press Enter.
Output:
Hello, World!
3. How it Works
Let's break down that single line of code:
print(): This is a built-in Python function that outputs whatever is inside the parentheses to the screen."Hello, World!": This is a string. Strings in Python must be surrounded by either single quotes (') or double quotes (").
4. Key Features of Python
| Feature | Description | | :--- | :--- | | Dynamically Typed | You don't need to declare variable types (like int or string). | | Object-Oriented | Everything in Python is an object. | | Platform Independent | Run the same code on Windows, macOS, and Linux. | | Extensive Libraries | "Batteries included" philosophy means standard libraries for almost everything. |
Practice Problems
- Modify the Output: Change the code to print your own name instead of 'Hello, World!'.
- Double Print: Write a script that prints "Python is fun!" on two separate lines using two
print()statements. - Basic Math: Python can also be used as a calculator. Try running
print(5 + 5). What is the result? - Error Identification: Try removing the quotes from the
printstatement (e.g.,print(Hello)). What happens when you run it?