Beyond Regular Matter. Click here

⚠️ Stay Safe Online

This website will never ask for money except for paid services enlisted here or collect personal information in other ways online or offline. Stay vigilant and protect yourself from cyber fraud. No paid service is enabled here now. Use this as a digital library made personally to support academic excellence.

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")

OUTPUT
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 TypeExample
Integer (int)5
Float (float)3.14
String (str)"hello"
Boolean (bool)True, False


Example:

a = 5
b = 2.5
c = "Einstein"
d = True

4. 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

OperatorMeaning
+Addition
-Subtraction
*Multiplication
/Division
//Floor Division
%Modulus
**Power

Example:

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......