Back to all posts

Python Basics Guide: Variables, Data Types, Typecasting, Input, Comments & Operators

Introduction Agar aap Python programming start kar rahe ho, toh sabse important foundation hai: Variables Data Types Typecasting User Input Comments & Print...

Introduction

Agar aap Python programming start kar rahe ho, toh sabse important foundation hai:

  • Variables

  • Data Types

  • Typecasting

  • User Input

  • Comments & Print

  • Operators

Ye sab concepts milke aapko strong base dete hain, jisse aap real-world applications bana sakte ho.


Variables & Data Types in Python

📌 Variable kya hota hai?

Variable ek container hai jo data store karta hai.

👉 Real life example:

  • Kitchen me dabba (container)

  • Usme sugar, rice, coffee store hota hai

Same way:

  • Variable me data store hota hai

Python
age = 34
name = "Harry"
gpa = 8.2

Data Types in Python

Python automatically data type detect karta hai (Dynamic Typing)

Common Data Types:

Type

Example

Meaning

int

10

Integer

float

8.5

Decimal number

str

"Hello"

Text

bool

True/False

Logical

Python
print(type(age))   # int
print(type(name))  # str

📏 Variable Naming Rules

✔ Valid:

Python
age = 20
_name = "test"
abc_123 = 10

❌ Invalid:

Python
34age = 10     # number se start nahi
age$ = 10      # special char allowed nahi

Rules:

  • Letter ya underscore se start hona chahiye

  • Numbers allowed hain (start me nahi)

  • Case sensitive hai (ageAge)


💡 Pro Tip (Developer Insight)

  • Meaningful names use karo:

Python
user_age = 25  # better than a = 25
  • Avoid Python keywords:

Python
# avoid this
if = 10

Typecasting (Data Type Conversion)

Typecasting kya hota hai?

Ek data type ko dusre data type me convert karna.

👉 Example:

Python
b = "34"   # string
c = int(b) # integer

Common Typecasting Functions

Function

Use

int()

convert to integer

float()

convert to decimal

str()

convert to string

bool()

convert to boolean


📌 Example

Python
d = 223
e = str(d)

print(type(e))  # str

⚠️ Common Mistake

Python
a = "10"
print(a + 5)  # ❌ error

✔ Fix:

Python
a = int(a)
print(a + 5)

💡 Real World Use

  • Form inputs (always string aata hai)

  • API responses

  • Database data processing


⌨️ User Input in Python

📌 Input Function kya hai?

User se data lene ke liye use hota hai.

Python
a = input("Enter number: ")

👉 Input always string return karta hai


⚠️ Important Concept

Python
a = input("Enter number: ")
print(a + 3)  # ❌ error

✔ Correct:

Python
a = int(input("Enter number: "))
print(a + 3)

📌 Multiple Inputs Example

Python
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print(a + b)

💡 Best Practice

  • Always prompt use karo:

Python
input("Enter your name: ")

💬 Comments, Print & Escape Sequences

📝 Comments kya hote hain?

Code me notes likhne ya kisi line ko ignore karne ke liye.

Python
# This is a comment

Multi-line:

Python
'''
This is multi-line comment
'''

🖨️ Print Function Advanced Use

Python
print("Hello", "World")

Default:

  • space add hota hai

Customize:

Python
print("Hello", "World", sep="-")

Output:

SQL
Hello-World

🔚 end Parameter

Python
print("Hello", end=" ")
print("World")

Output:

SQL
Hello World

🔤 Escape Sequence Characters

Code

Meaning

\n

new line

\t

tab

\

backslash

Python
print("Hello\nWorld")

➕ Operators in Python

🔢 Arithmetic Operators

Python
a = 34
b = 2

print(a + b)   # 36
print(a - b)   # 32
print(a * b)   # 68
print(a / b)   # 17.0
print(a % b)   # remainder
print(a // b)  # floor division
print(a ** b)  # power

⚖️ Comparison Operators

Python
print(a > b)   # True
print(a == b)  # False
print(a != b)  # True

👉 Always returns Boolean (True/False)


🔗 Logical Operators

Python
print(True and False)  # False
print(True or False)   # True
print(not True)        # False

🧮 Assignment Operators

Python
a = 10
a += 5   # 15
a -= 3   # 12
a *= 2   # 24

💡 Developer Tips

  • == vs = confusion avoid karo

  • Floor division (//) interviews me pucha jata hai

  • Boolean logic backend filtering me useful hota hai


🧑‍💻 Practical Tips (Real World)

✔ Common Mistakes

  • Input ko integer convert na karna

  • Variable naming confusing rakhna

  • = aur == mix kar dena


✔ Best Practices

  • Clean code likho

  • Comments use karo

  • Small programs likh ke practice karo


✔ Interview Questions

  • Python dynamic typing kya hai?

  • Difference between = and ==?

  • // vs / difference?

  • Input always string kyun hota hai?


📌 Summary

Aaj humne Python ke core basics cover kiye:

  • Variables = data containers

  • Data Types = int, float, string, bool

  • Typecasting = data conversion

  • Input = user se data lena

  • Comments = code readability

  • Operators = calculations & logic

👉 Ye sab concepts milke Python ka strong foundation banate hain.


🏁 Final Advice

Programming ratne ka game nahi hai — samajhne ka game hai.

👉 Roz thoda code likho, tabhi mastery aayegi.


🔖 Tags

0 likes

Rate this post

No rating

Tap a star to rate

0 comments

Latest comments

0 comments

No comments yet.

Keep building your data skillset

Explore more SQL, Python, analytics, and engineering tutorials.