Step 1: Variables in Python
Variables store data that your program can use. Python is dynamically typed, so you don't need to declare types explicitly.
name = "Alisha"
age = 30
height = 5.6
Note: Variable names cannot start with a number and are case-sensitive.
Step 2: Data Types
Python has several built-in data types:
- int – integers, e.g.,
age = 30
- float – decimal numbers, e.g.,
height = 5.6
- str – strings, e.g.,
name = "Alisha"
- bool – boolean, e.g.,
is_active = True
- list – ordered collection, e.g.,
numbers = [1,2,3]
- dict – key-value mapping, e.g.,
person = {"name":"Alisha", "age":30}
Step 3: Input and Output
Use input() to get user input and print() to display output:
name = input("Enter your name: ")
print("Welcome,", name)
Enter your name: Alisha
Welcome, Alisha
Step 4: Operators
Python supports various operators:
- Arithmetic: +, -, *, /, %, **, //
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
- Assignment: =, +=, -=, *=, /=
a = 10
b = 3
print("Sum:", a + b)
print("Power:", a ** b)
Sum: 13
Power: 1000
Step 5: PyCharm Project Example
Directory layout and simple script:
MyPythonProject
├── main.py
├── data.txt
└── requirements.txt
# main.py
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
print("Difference =", a - b)
Enter first number: 8
Enter second number: 5
Sum = 13
Difference = 3
✔ End of Day 2 – Variables, data types, operators, input/output understood and tested!