Downloads are text notes. Choose Save as PDF in your browser’s print dialog for a PDF copy.
Understand the concept
A variable is a name bound to an object. In score = 10, score refers to an integer object. Python does not require a type declaration; type(score) tells you the current object’s type. Reassigning score changes what the name refers to.
Use int for whole numbers, float for decimal approximations, str for text, and bool for True or False. Quotes distinguish text from a number: "10" is a string, while 10 is an integer. input() returns text, so convert deliberately with int() or float() when a calculation needs a number.
Use meaningful names such as lessons_completed. Assignment uses =; comparison uses ==. Converting invalid text, such as int("hello"), raises ValueError. Validate user input instead of assuming every entry is numeric.
Variable ko ek naam ki tarah samjho jo kisi object se juda hai. score = 10 mein score naam integer 10 ko refer karta hai. Python mein type pehle declare nahi karna padta. type(score) se current object ka type check kar sakte ho. Dobara assignment karne par naam naye object ko refer karega.
Whole numbers ke liye int, decimal approximations ke liye float, text ke liye str aur True/False ke liye bool use hota hai. "10" text hai; 10 number hai. input() hamesha text deta hai. Calculation karni ho toh zarurat ke hisaab se int() ya float() se convert karo.
lessons_completed jaise clear names rakho. = value assign karta hai, == comparison karta hai. int("hello") se ValueError aayega, kyunki har text valid number nahi hota. User input ko validate karo.
Run the example and attempt the exercise before marking this lesson complete.
pass the idea on
What did this make you think?
You review and publish the post yourself. Instagram uses your device’s share menu when available; otherwise copy the text and link. Facebook opens the link composer, where you add your thoughts.