Python Notes: Basics
PHYSICXION: basic python notes
Basic Python Notes
What is Python?
Python is a high-level, interpreted programming language widely used in:
- Scientific computing
- Artificial Intelligence
- Web development
- Data analysis
- Automation
- Physics simulations
1. Writing Your First Python Program
print("Hello World")
Hello World
print() is used to display output on the screen.2. Variables in Python
Variables store data.
x = 10
name = "Physics"
pi = 3.14
Rules for Variables
Cannot start with a number
No spaces allowed.
Case-sensitive. Example:
age = 20
Age = 30
Both are different variables.3. Data types
These are the primary basic data types used in Python, classified in the following table. There are more data types like list, tuple, range, frozenset, binary types, and null types.
Data Type Example Integer (int) 5Float (float) 3.14String (str) "hello"Boolean (bool) True, False
int)5float)3.14str)"hello"bool)True, FalseExample:
a = 5
b = 2.5
c = "Einstein"
d = True4. Taking User Input
name = input("Enter your name: ")
print(name)
Numerical Input
x = int(input("Enter a number: "))
For decimal numbers:
x = float(input("Enter value: "))
5. Basic Operator
Arithmetic Operators| Operator | Meaning |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
// | Floor Division |
% | Modulus |
** | Power |
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)
print(a ** b)
6. Conditional Statements
if Statement
x = 10
if x > 5:
print("x is greater than 5")
if-else
x = 2
if x % 2 == 0:
print("Even")
else:
print("Odd")
if-elif-else
marks = 75
if marks >= 90:
print("A")
elif marks >= 70:
print("B")
else:
print("C")7. Loops in Python
for loop
for i in range(5):
print(i)
OUTPUT
0
1
2
3
4
while loop
x = 1
while x <= 5:
print(x)
x += 1
OUTPUT
Run started
Initializing environment
Installing packages
Running code
1
2
3
4
5
Run completed in 43.69999998807907ms
from functions and advanced topics to be included here......
.png)
Join the conversation