Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Python Basics - Quick Revision Notes


📌 Variables

Variables store data.

name = "Hello"
age = 20
price = 99.99

✅ Rules:

  • 🔤 Start with a letter or _
  • 🔢 Cannot start with a number
  • 🚫 No spaces
  • 🔠 Case-sensitive (nameName)
  • ❌ Don't use keywords (if, for, class)

📌 Data Types

Data Type Example
🔢 int 10
💰 float 10.5
🔤 str "Hello"
✅ bool True
📋 list [1,2,3]
📦 tuple (1,2,3)
🎯 set {1,2,3}
📖 dict {"a":1}
⚡ complex 2+3j
🚫 NoneType None
print(type(10))

📌 Type Casting

Convert one data type to another.

int("10")
float("10.5")
str(100)
bool(1)
list("Python")
tuple([1,2])
set([1,2,2])
dict([("a",1)])

📌 User Input

name = input("Enter Name: ")
age = int(input("Enter Age: "))
price = float(input("Enter Price: "))

📌 Operators

➕ Arithmetic

+
-
*
/
%
//
**

⚖️ Comparison

==
!=
>
<
>=
<=

🔗 Logical

and
or
not

✏️ Assignment

=
+=
-=
*=
/=

🆔 Identity

is
is not

📦 Membership

in
not in

📌 Calculator Logic

if op == "+":
    print(a + b)
elif op == "-":
    print(a - b)
elif op == "*":
    print(a * b)
elif op == "/":
    print(a / b)

📌 Useful Functions

print()
input()
type()
len()
int()
float()
str()
bool()
list()
tuple()
set()
dict()
range()
id()

📌 Multiple Variables

a, b, c = 10, 20, 30

x = y = z = 100

Swap Variables

a, b = b, a

📌 String Join

letters = ["P","y","t","h","o","n"]

print("".join(letters))

📌 Dictionary

student = {
    "name": "Hit",
    "age": 20
}

Keys

student.keys()

Values

student.values()

Items

student.items()

📌 List

numbers = [10,20,30]

📌 Tuple

data = (10,20,30)

📌 Set

data = {10,20,30}

No duplicate values.


📌 Boolean

True
False

🎯 Quick Remember

  • 📦 Variable → Stores data
  • 🔤 str → Text
  • 🔢 int → Whole number
  • 💰 float → Decimal number
  • bool → True/False
  • 📋 list → Ordered, Mutable
  • 📦 tuple → Ordered, Immutable
  • 🎯 set → Unique values
  • 📖 dict → Key : Value
  • 🔄 Type Casting → Change data type
  • ⌨️ input() → Take user input
  • 🖨️ print() → Display output
  • 🏷️ type() → Check data type

🚀 Python Formula Sheet

# Variable
x = 10

# Input
name = input()

# Integer Input
age = int(input())

# Float Input
price = float(input())

# Print
print(name)

# Data Type
type(x)

# Type Casting
int()
float()
str()
bool()
list()
tuple()
set()
dict()

# Swap
a, b = b, a

Golden Rule:
Declare → Input → Process → Output

Releases

Packages

Contributors

Languages