Introduction to Python and Basic Syntax
Introduction to Python and Basic Syntax
Welcome to your first lesson on Python! This handout will guide you through the basics of
Python, including its syntax, variables, data types, and basic operators. Let's get started!
1. Overview of Python
History of Python
Created by Guido van Rossum and first released in 1991.
Named after the British comedy group Monty Python.
Features of Python
Easy to Learn and Use: Simple syntax resembling plain English.
Interpreted Language: Executes code line by line.
Cross-Platform: Works on Windows, macOS, and Linux.
Extensive Libraries: Supports web development, data analysis, machine learning, etc.
Community Support: Large and active community for help and resources.
Applications of Python
Web Development: Using frameworks like Django and Flask.
Data Science and Machine Learning: Libraries like Pandas, NumPy, and TensorFlow.
Automation: Automating repetitive tasks with scripts.
Game Development: Creating games with libraries like Pygame.
Scripting: Writing small scripts for automation.
1. Setting Up the Python Environment
Installation
1. Download Python: Visit python.org and download the latest version.
2. Install Python: Follow installation instructions and check "Add Python to PATH".
IDE Setup
PyCharm: A powerful IDE with many features.
VS Code: A lightweight editor with Python support.
Jupyter Notebook: Ideal for data science and interactive coding.
Python Syntax
Example 1:
Example 2:
Example 3:
Indentation in Python
Indentation defines code blocks.
Example 1:
Example 2:
Example 3:
4. Basic Operators
Arithmetic Operators
Addition:
Example 1: 5 + 3 results in 8
Example 2: 10 + 20results in 30
Example 3: results in 0
Subtraction:
Example 1: results in 2
Example 2: 20 - 10results in 10
Example 3: results in
Multiplication:
Example 1: 5 * 3 results in 15
Example 2: 10 * 2 results in 20
Example 3: 5 * 5 results in
Division:
Example 1: results in
Example 2: 10 / 2 results in 5
Example 3: results in
Comparison Operators
Equal to: (==)
Example 1: 5 == 5 is True
Example 2: 10 == 5 is False
Example 3: -5 == -5 is True
Not equal to: (!=)
Example 1: 5 != 3 is True
Example 2: 10 != 10 is False
Example 3: -5 != 5 is True
Example 3: -5 > -10 is True
Less than: (<)
Logical Operators
and: Both conditions must be true.
Example 1: is
Example 2: is
Example 3: is
or: At least one condition must be true.
Example 1: is
Example 2: is
Example 3: is
not: Reverses the condition.
Example 1: is
Example 2: is
Example 3: is
Conclusion
You've completed your first lesson on Python! We covered:
Keep practicing, and soon you'll be writing Python code like a pro!
Next Steps
In the next lesson, we'll explore control structures like loops and conditionals. Happy coding!