Class Notes: Introduction to Python Programming
1. History of Python
- Creator: Python was created by Guido Van Rossum.
- Release Date: The language was released in February 1991.
- Name Origin: Python got its name from a BBC comedy series from the 1970s called “Monty Python’s Flying Circus.”
2. Python’s Programming Approach
- Procedural and Object-Oriented: Python supports both Procedural and Object-Oriented approaches to programming, making it versatile for various types of applications.
- Free to Use: Python is free and open-source, meaning anyone can use and modify it without cost.
3. Influences on Python
- ABC Language: Python is influenced by the ABC language, which was designed as a replacement for BASIC.
- Modula-3: Another significant influence on Python is Modula-3, which contributed to Python’s design.
4. Applications of Python
Python is used in many diverse fields, including:
- Scripting
- Web Applications
- Game Development
- System Administration
- Rapid Prototyping
- GUI Programs
- Database Applications
5. Python Distributions
- CPython: The default installation available from python.org is called CPython, which includes the Python interpreter, Python IDLE (Python GUI), and Pip (package installer).
- Anaconda: Anaconda is a highly recommended distribution that comes with many preloaded packages and libraries like NumPy, SciPy, and Pandas.
- Popular IDEs: IDEs like Spyder and PyCharm are popular for Python development. Spyder is available as part of the Anaconda distribution.
6. Python Working Modes
- Interactive Mode:
- Python executes commands immediately after they are entered.
- Commands are typed at the IDLE prompt (
>>>
), and Python provides instant feedback.
- Script Mode:
- Multiple commands are saved in a file, and the entire program can be executed at once.
- Script mode is ideal for writing longer pieces of code that need to be saved and reused.
7. Interactive Mode Example
- Command:
- Typing
>>> 20 + 30
at the IDLE prompt will output50
.
- Typing
- Script Mode Example:
- A simple Python program to print “Hello World!” is written in a file and executed to see the output.
8. Printing in Python
- Python 3.x: Uses the
print()
function to display output.- Example:
print("Welcome to Python")
will display “Welcome to Python.”
- Example:
- String Enclosures: Python allows both single and double quotes for enclosing strings, but the opening and closing quotes must match.
- Example:
print('Python rocks!')
will display “Python rocks!”
- Example:
9. Key Points to Remember
- Case-Sensitivity: Python is case-sensitive, treating
m
andM
as different entities. - Recall Commands: Use the up (
↑
) and down (↓
) arrow keys to recall and execute previous commands in interactive mode. - Interactive vs. Script Mode:
- Interactive Mode: Best for beginners and testing small pieces of code.
- Script Mode: Best for writing and saving longer programs.
10. Sample Python Code
# My First Program
print("Hello World!")
- Comment: Lines starting with
#
are comments and are ignored by the interpreter. - Output: The script above will output “Hello World!”
11. Questions for Review
- Who developed the Python programming language?
- Is Python an object-oriented language?
- What does it mean that Python is a high-level interpreted language?
- What does cross-platform mean?
- What is the difference between interactive mode and script mode in Python?