🟡 Advanced Python  ·  Lesson 30

Python Code Testing और Debugging

Testing और Debugging क्या है?

Testing और Debugging ka matlab hai: Testing checks whether code works correctly. Debugging helps find and fix errors. Simple words me, ye topic practical Python programs likhne me direct use hota hai.

Is topic ko sirf definition ke liye nahi, balki checking code automatically jaise real examples ke liye practice karein.

यह क्यों सीखना जरूरी है?

  • Ye checking code automatically me kaam aata hai.
  • Ye finding wrong output se bhi connected hai.
  • Isse aap code ka output aur errors better samajh paate hain.

Important Terms

TermMeaning
assertStatement used to verify that a condition is true.
unit testSmall test that checks one part of code.
bugA mistake in code that causes wrong behavior.
tracebacktraceback is an important term in this topic.
print debuggingprint debugging is an important term in this topic.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
def add(a, b):
    return a + b
assert add(2, 3) == 5
assert add(-1, 1) == 0
print("All tests passed")

Complete Example Program

Python – testing-debugging.py
def add(a, b):
    return a + b

assert add(2, 3) == 5
assert add(-1, 1) == 0

print("All tests passed")

Expected Output

All tests passed

Program Explanation

  • def add(a, b): creates a reusable function.
  • return a + b sends a result back from the function.
  • assert add(2, 3) == 5 performs the next step of the program logic.
  • assert add(-1, 1) == 0 performs the next step of the program logic.
  • print("All tests passed") displays information or calculated result on the screen.

Practical Uses

  • Checking code automatically.
  • Finding wrong output.
  • Improving reliability.

Common Mistakes

  • Making code complex when a simple function or class is enough.
  • Not handling possible errors or edge cases.
  • Mixing project dependencies instead of using a virtual environment.

Practice Tasks

  1. Program ko testing-debugging.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. checking code automatically par ek छोटा example banayen.
  4. Logic ko apne words me 5 lines me likhein.

सारांश

Testing and Debugging ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.

← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.