Python Basics - Beginner Explanation
1. What is Python?
- Python is a high-level, easy-to-read programming language.
- It is used for web development, automation, data science, AI, and more.
- Python was created by Guido van Rossum and released in 1991.
2. Why Learn Python?
- Simple and readable syntax (like English).
- Large community and lots of libraries.
- Used by companies like Google, Instagram, Netflix, NASA.
3. Installing Python
- Visit https://www.python.org and download the latest version.
- Use an IDE like IDLE (built-in), VS Code, or PyCharm.
- To run code: use an editor or Python shell.
4. Your First Program
print("Hello, World!")
- This prints a message to the screen.
- `print()` is a built-in function used for output.
5. Comments in Python
# This is a comment
- Comments are ignored by Python and used for explaining code.
6. Variables
- Variables store values.
Example:
name = 'John'
age = 15
7. Data Types
- int: Whole numbers (e.g., 5, 100)
- float: Decimal numbers (e.g., 3.14)
- str: Text in quotes (e.g., "Hello")
- bool: True or False
8. Input and Output
name = input("What is your name? ")
print("Hello", name)
- `input()` gets user input as a string.
9. Type Conversion
num = int(input('Enter a number: '))
print(num * 2)
- Use int(), float(), str() to change types.
10. Operators
+ Addition (a + b)
- Subtraction (a - b)
* Multiplication (a * b)
/ Division (a / b)
// Floor Division (a // b)
% Modulus (a % b)
** Power (a ** b)
11. Practice Tasks
- Write a program that asks for your name and age.
- Write a program that adds two numbers input by the user.
- Try printing your favorite quote using `print()`.