1.2.2 · HinglishIntroduction to Programming (Python)

`print()`, comments, code structure

1,798 words8 min readRead in English

1.2.2 · Coding › Introduction to Programming (Python)


1. print() — insaan se baat karna

Behaviour ko first principles se derive karna

Hum guess nahi karte ki print() kya karta hai — hum sabse chhote cases try karke reasoning karte hain.

print("Hello")        # 1 argument: a string
print(42)             # 1 argument: a number
print("Sum:", 2 + 3)  # 2 arguments
print()               # 0 arguments

print("Sum:", 2 + 3) Sum: 5 kyun dikhata hai?

  • Step 1: Python pehle har argument ko evaluate karta hai. "Sum:" "Sum:" hi rehta hai; 2 + 3 5 ban jaata hai. Yeh step kyun? Python hamesha value compute karta hai pehle, phir use function ko deta hai.
  • Step 2: print multiple arguments ko by default ek space se jodta hai aur unhe likhta hai.
  • Step 3: print end mein automatically ek newline (\n) add karta hai. Kyun? Taaki har print apni alag line par aaye — yahi sabse common zaroorat hoti hai.

2. Comments — insaanon ke liye notes

# This whole line is ignored.
print("Hi")          # everything after # on THIS line is ignored
radius = 5           # store the radius in cm
area = 3.14159 * radius ** 2   # πr²

3. Code structure — Python ek file kaise padhta hai

Figure — `print()`, comments, code structure

Active recall — flashcards

print Python mein kis tarah ka construct hai?
Ek built-in function.
print() ke parentheses ke andar jo values hoti hain unhe kya kehte hain?
Arguments.
print by default apne arguments ke baad kya add karta hai?
Ek newline (end="\n").
print by default multiple arguments ke beech kya rakhta hai?
Ek single space (sep=" ").
print() ki return value kya hoti hai?
None (iska asli kaam text dikhane ka side effect hai).
print ko naye line par jaane se kaise rokein?
end="" pass karo (ya koi bhi string jo tum chahte ho).
Single-line comment kaunse symbol se shuru hota hai?
#.
Kya Python comments execute karta hai?
Nahi — unhe bilkul ignore kiya jaata hai.
print(Hello) (bina quotes) kyun fail hota hai lekin print("Hello") kaam karta hai?
Bina quotes ke Hello ko ek variable name maana jaata hai → NameError; quotes use literal string banate hain.
Statements by default kis order mein run hote hain?
Top to bottom, ek line at a time.
print("A","B",sep="-") kya output deta hai?
A-B.
Ek achha comment ___ explain karta hai, obvious ___ nahi.
why ; what.

Recall Feynman: ek 12-saal ke bachche ko explain karo (hidden)

Socho computer ek super-fast lekin andha helper hai. Woh apne dimag mein maths karta hai aur cheezein yaad rakhta hai, lekin tum kuch nahi dekh sakte. print() helper se yeh kehne jaisa hai: "woh bol do zor se taaki main sun sakun!" — sirf isi tarah tum pata laga sakte ho ki use kya pata hai. Ek comment (#) un sticky notes ki tarah hai jo tum apni instructions ke paas likhte ho: helper unhe padhke aage badh jaata hai, woh sirf tumhare liye hain taaki tum yaad rakh sako ki har step kyun likha. Aur helper hamesha tumhari instructions page ke upar se neeche, order mein follow karta hai, kabhi aage nahi jump karta.


Connections

  • Variables and Assignmentprint woh dikhata hai jo variables hold karte hain.
  • Strings and Quotes — text ko " " ki zaroorat kyun hai.
  • f-strings and String Formattingprint ke liye text banane ke sundar tarike.
  • Functions, Arguments, and Return Valuesprint ek function hai; sep/end keyword arguments hain.
  • Indentation and Code Blocks — structure rule jo if/for use karta hai.
  • None and Truthiness — kyun print None return karta hai.

Concept Map

runs

needs output

needs human notes

takes

Python first

then joined by

then adds

builds

controls

return value is

so

ignored by

Program is list of instructions

Top to bottom, one line at a time

print() function

Comments

Arguments in parentheses

Evaluate each value

sep default space

end default newline

Output string on screen

Continue on same line if changed

None not the value

Store values with x = 5 instead