Variables and Data Types in Python โ€“ Har Detail #3 || Python ka Pitara || DeathCode - DeathCode

Variables and Data Types in Python โ€“ Har Detail #3 || Python ka Pitara || DeathCode

"To bhai pichhle video me humne Python ka syntax samjha, apna pehla program likha, aur Python ki simplicity ko feel kiya.

Ab baat karte hain Python ke dil ki โ€” Variables aur Data Types.

Inhi dono ke base pe poori programming chalti hai โ€” so agar ye part achhe se samajh gaya, to samajh lo Python ka foundation ban gaya. ๐Ÿ’ช"


๐Ÿง  Section 1: What is a Variable?

name = "DeathCode"
age = 21
pi = 3.14

"Variable matlab ek container โ€” jisme hum koi value store karte hain.

Python me variable banane ke liye sirf naam likho, = lagao, aur value assign kar do โ€” itโ€™s that simple.

Python automatically samajh leta hai ki ye kis type ka data hai โ€” isko kehte hain dynamic typing."

๐Ÿ“œ Rules for Creating Variables:

  • Variable ka naam letter ya underscore (_) se start hona chahiye.
  • Variable ka naam number se start nahi ho sakta.
  • Variable name me sirf alphabets, numbers, aur underscores allowed hain.
  • Python keywords (jaise if, for, while) variable naam nahi ban sakte.
  • Variable names are case-sensitive (name aur Name alag-alag hain).
  • Naam meaningful aur readable rakhna best practice hai.

Example:

valid_name = 10
_valid = 20
name1 = "Python"
# 1name = 5  # โŒ Invalid

โš™๏ธ Section 2: Python is Dynamically Typed

x = 10
x = "Hello"

"Yahan pehle x ek number tha, fir ek string ban gaya. Python ne kuch complain nahi kiya!

Kyunki Python me aap variable ke type ko baar baar badal sakte ho.

Dynamic Typing ka yahi magic hai โ€” aur isi wajah se Python beginners ke liye super-friendly hai."


๐Ÿ”ข 1. What are Data Types?

"Har variable jo aap Python me create karte ho, uska koi na koi data type hota hai.

Kisi variable me agar number hai to wo numeric type hoga, agar text hai to string, aur agar multiple values store karni hai to list, tuple, ya dict use hota hai.

Python me aapko explicitly type batani nahi padti โ€” wo khud smartly detect kar leta hai."

x = 10      # int
y = "hello" # str
z = [1, 2]  # list

๐Ÿ’พ 2. Built-in Data Types in Python

Category Data Types
Text Type str
Numeric Types int, float, complex
Sequence Types list, tuple, range
Mapping Type dict
Set Types set, frozenset
Boolean Type bool
Binary Types bytes, bytearray, memoryview
None Type NoneType
print(type(5))         # int
print(type(3.14))      # float
print(type("hello"))   # str
print(type([1, 2]))    # list
print(type({"a": 1}))  # dict
print(type(True))      # bool

๐Ÿ” 3. Individual Data Types + Common Methods

๐Ÿ”น int, float, complex

a = 5
b = 3.14
c = 3 + 4j
 
print(a + b)         # 8.14
print(c.real)        # 3.0
print(c.imag)        # 4.0

๐Ÿ”น str (String)

name = "DeathCode"
print(name.upper())    # 'DEATHCODE'
print(name.lower())    # 'deathcode'
print(name[0])         # 'D'
print(name[1:5])       # 'eath'
print("Code" in name)  # True

"Strings immutable hote hain โ€” yaani once created, directly modify nahi kar sakte."

๐Ÿ”น bool

a = True
b = False
 
print(a == 1)       # True
print(b == 0)       # True
print(bool(""))     # False
print(bool("hi"))   # True

๐Ÿ”น list

nums = [1, 2, 3, 2]
nums.append(4)
nums.remove(2)      # removes first occurrence
print(nums)         # [1, 3, 2, 4]

Useful Methods:

  • append(), insert(), pop(), remove(), sort(), reverse(), count()

๐Ÿ”น tuple

t = (1, 2, 3)
print(t[1])           # 2
print(len(t))         # 3

"Tuple is immutable, jaise ek frozen list."

๐Ÿ”น set

s = {1, 2, 3, 2, 1}
print(s)              # {1, 2, 3}
s.add(4)

"Set unordered hota hai aur duplicates allow nahi karta."

๐Ÿ”น dict

user = {"name": "Amit", "age": 23}
print(user["name"])       # Amit
user["city"] = "Delhi"
print(user.get("age"))    # 23

Useful Methods: keys(), values(), items(), update(), pop(), get()

๐Ÿ”น range, bytes, None

print(list(range(5)))  # [0, 1, 2, 3, 4]
a = None
print(type(a))         # <class 'NoneType'>

๐Ÿ› ๏ธ 4. How to Explore Methods Yourself

print(dir(str))
help(str.upper)

"dir() aur help() se kisi bhi data type ke methods aur documentation explore kar sakte ho."


๐Ÿง  5. Real-life Examples & Use-Cases

"Shopping list banani ho to list use karo, user ka profile banana ho to dict use karo, GPS coordinates store karne ho to tuple use karo โ€” real duniya me Python ke data types har jagah kaam aate hain."


๐ŸŒŸ 6. Practice Questions

"Video ke end me kuch simple practice questions diye hain. Unka jawab aap YouTube ke comment section me likh sakte ho! Main personally check karunga ๐Ÿ‘."

  1. Ek list banao jisme 5 numbers ho โ€” unka sum print karo.
  2. Ek dictionary banao jisme name aur age ho โ€” aur age ko 1 se badhao.
  3. Ek string lo aur usse reverse karke print karo.
  4. Ek set banao aur ek duplicate value add karke dekho.
  5. Ek tuple ko unpack karke 3 variables me assign karo.

๐ŸŽฎ Outro

"Agar aapko video accha laga ho to like, comment, aur share karna mat bhoolna!

Aur agar koi doubt hai, YouTube comment section me likhna โ€” main khud personally reply karunga.

Agle video me hum dekhenge Python ke Conditional Statements ka powerful world!

Tab tak ke liye โ€” Keep Learning, Keep Coding! ๐Ÿ”ฅ"

ยฉ 2024 DeathCode. All Rights Reserved.