1971 - 981 - DOC - Introduction To Python and Basic Syntax
1971 - 981 - DOC - Introduction To Python and Basic Syntax
Student Handout
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.
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:
print("Hello, World!")
Example 2:
print("Python is fun!")
Example 3:
Indentation in Python
Indentation defines code blocks.
Example 1:
if 5 > 3:
print("5 is greater than 3")
Example 2:
for i in range(5):
print(i)
Example 3:
while True:
break
5. Basic Operators
Arithmetic Operators
Addition: +
Example 1: 5 + 3 results in 8
Example 2: 10 + 20 results in 30
Example 3: -5 + 5 results in 0
Subtraction: -
Example 1: 5 - 3 results in 2
Example 2: 20 - 10 results in 10
Example 3: -5 - 5 results in -10
Multiplication: *
Example 1: 5 * 3 results in 15
Example 2: 10 * 2 results in 20
Example 3: -5 * 5 results in -25
Division: /
Example 1: 5 / 3 results in 1.6667
Example 2: 10 / 2 results in 5
Example 3: -10 / 5 results in -2
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
Greater than: >
Example 1: 5 > 3 is True
Example 2: 10 > 20 is False
Example 3: -5 > -10 is True
Less than: <
Example 1: 5 < 3 is False
Example 2: 10 < 20 is True
Example 3: -5 < -10 is False
Logical Operators
and: Both conditions must be true.
Example 1: (5 > 3) and (3 > 1) is True
Example 2: (5 > 3) and (3 < 1) is False
Example 3: (5 < 3) and (3 > 1) is False
or: At least one condition must be true.
Example 1: (5 > 3) or (3 < 1) is True
Example 2: (5 < 3) or (3 > 1) is True
Example 3: (5 < 3) or (3 < 1) is False
not: Reverses the condition.
Example 1: not (5 > 3) is False
Example 2: not (5 < 3) is True
Example 3: not (3 == 3) is False
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!
😊