One of the most common question types in Class 11 and 12 Computer Science board exams is: 'What will be the output of the following Python code?' These questions test whether you can mentally trace through code step by step without running it on a computer.
In Python, the print() function by default adds a newline character at the end. Using print(x, end='') or print(x, end=' ') changes this behavior โ a very common source of tricky output questions!
Follow this systematic approach:
Example 1 โ Simple Loop:
for i in range(1, 5):
print(i * 2)
Output:
2
4
6
8
(range(1,5) gives 1,2,3,4 โ 5 is excluded)
Example 2 โ String Slicing:
s = 'PYTHON'
print(s[1:4])
print(s[::-1])
Output:
YTH
NOHTYP
(s[1:4] โ characters at index 1,2,3; s[::-1] โ reversed string)
Example 3 โ Nested Loop:
for i in range(1, 4):
for j in range(1, 4):
print(i * j, end=' ')
print()
Output:
1 2 3
2 4 6
3 6 9
range(n) gives 0 to n-1, NOT 0 to n7//2 = 3 (not 3.5)**1024**. The `**` operator is Python's exponentiation (power) operator. 2ยนโฐ = 1024.
Evolution of Computers: The 5 Generations
Learn about the evolution of computers from massive room-sized vacuum tubes to modern AI. Explore the 5 generations of computer history.
What are Output Devices? (Definition and Examples)
Learn the definition of computer output devices. Find clear examples like monitors, printers, speakers, and projectors, explained for students.
What is a Web Browser? (With Examples)
Learn what a web browser is and see popular examples of web browsers like Google Chrome, Safari, Mozilla Firefox, and Microsoft Edge.
Fibonacci Series in C (Code and Logic)
Learn how to write a Fibonacci series program in C. Understand the logic with both iterative and recursive methods with complete code examples.
What is Firewall Authentication?
Learn what firewall authentication is in computer networks. Understand how it blocks unauthorized hackers while allowing verified users to access internal company data.
Turn this guide into revision flashcards, a practice exam, or an AI-generated podcast โ free, no signup required.