Introduction To Python — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Introduction To Python — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is Python primarily used for?
Correct Answer: Option B — Data analysis
Detailed Academic Explanation:
Python is primarily used for data analysis , among other things. It provides powerful libraries such as NumPy, Pandas, and Matplotlib, which are widely used in the field of data science and analytics. These libraries offer tools for data manipulation, analysis, and visualization, making Python a popular choice for tasks such as statistical analysis, machine learning, and data mining. While Python can be used for a variety of purposes including web development, automation, and scripting, its versatility and rich ecosystem make it particularly well-suited for data-related tasks.
💡Key Conceptual Anchor:Introduction To Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Who developed Python Programming Language?
Correct Answer: Option C — Guido van Rossum
Detailed Academic Explanation:
Python Programming Language was developed by Guido van Rossum . He initiated the development of Python in the late 1980s and released the first version in 1991. Since then, Python has grown into one of the most popular programming languages worldwide, known for its simplicity, readability, and versatility.
💡Key Conceptual Anchor:Introduction To Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is an advantage of Python?
Correct Answer: Option C — It has a large standard library
Detailed Academic Explanation:
The question asks about an advantage of Python. An advantage is something that makes Python good or easy to use compared to other programming languages. Correct Answer: Option C: It has a large standard library This is the correct answer because Python comes with a huge collection of pre-written code called the "standard library". Think of it like a toolbox that comes packed with all sorts of useful tools already inside. Want to work with files? There's a tool for that. Want to work with dates and times? There's a tool for that. Want to send emails or build a website? There are tools for those too! This means you don't have to write everything from scratch, which saves a lot of time and effort when you're building programs. It makes Python very powerful and versatile for many different types of projects. Why other options are incorrect: Option A: It compiles to machine code Python is what we call an "interpreted" language , not a traditionally "compiled" one like C++ or Java (which has its own way of compiling). When you run Python code, an "interpreter" program reads your code line by line and executes it directly. It doesn't first turn your entire program into a machine-readable file (called "machine code") before running it. While Python does convert code into something called "bytecode" internally, this isn't the same as compiling directly to machine code, which is usually faster for execution but less flexible for development. So, this is not an advantage in the way the option implies. Option B: It enforces strict typing Python uses something called "dynamic typing" . This means you don't have to explicitly tell Python what *type* of data a variable will hold (like "this variable will store a number" or "this variable will store text"). Python figures out the type of data as your program runs. "Strict typing" usually refers to languages where you *must* declare variable types, and the system strictly enforces them before the program even runs. Python's dynamic typing is often seen as an advantage for its flexibility and speed of development, but "strict typing" is not a characteristic of Python. Option D: It requires extensive memory management This is actually the opposite of the truth for Python ! Python has "automatic memory management" . This means you, as the programmer, generally don't need to worry about telling the computer when to free up memory after you're done using variables or objects. Python handles all of that automatically in the background using a process called "garbage collection". This is a huge advantage because it prevents common programming errors related to memory and makes Python much easier to learn and use compared to languages like C++ where you often have to manage memory manually. So, "requiring extensive memory management" would be a disadvantage, not an advantage, and Python avoids it.
💡Key Conceptual Anchor:Introduction To Python
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the role of the Python interpreter?
Correct Answer: Option C — To execute Python code line by line
Detailed Academic Explanation:
Option C is the correct answer. The Python interpreter is responsible for reading and executing Python programs. It processes the source code, translates it into an intermediate form (bytecode in CPython), and executes the instructions. From a programmer's perspective, the interpreter executes the program line by line , allowing errors to be detected during execution and making Python an interpreted language. Why Option A is incorrect: The Python interpreter does not convert Python code directly into assembly language . Assembly code is generated by low-level language compilers, whereas Python uses an interpreter that works with Python source code and bytecode. Why Option B is incorrect: Although the Python runtime automatically manages memory using mechanisms such as reference counting and garbage collection , memory allocation is not the primary role of the Python interpreter . Its main purpose is to execute Python programs. Why Option D is incorrect: In the CPython implementation, Python source code is first compiled into bytecode before execution. However, the question asks for the role of the Python interpreter , whose primary function is to execute the code. Compiling source code into bytecode is only one step in the execution process and is not the interpreter's main role as described in this question. Therefore, the primary role of the Python interpreter is to execute Python code, making Option C the correct answer.
💡Key Conceptual Anchor:Introduction To Python
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which programming paradigm is supported by Python?
Correct Answer: Option D — Multiple paradigms
Detailed Academic Explanation:
Python supports multiple paradigms . Python is a versatile language that accommodates different programming styles and paradigms, including imperative, functional, and object-oriented programming. This flexibility allows programmers to choose the most suitable approach for solving a particular problem. While Python is primarily an imperative language, it also incorporates features from other paradigms, such as support for higher-order functions and lambda expressions, making it suitable for functional programming. Additionally, Python's object-oriented features enable the creation of classes and objects, facilitating object-oriented programming. Overall, Python's support for multiple paradigms contributes to its widespread adoption and popularity among developers.
💡Key Conceptual Anchor:Introduction To Python
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax used to write comments in Python?
Correct Answer: Option C — # Comment
Detailed Academic Explanation:
In Python, the syntax used to write comments is # Comment . Comments in Python are indicated by the pound sign (#) followed by the text of the comment. Anything following the # symbol on a line is considered a comment and is ignored by the Python interpreter during execution. Comments are used to add explanatory notes or annotations within the code to make it more readable and understandable for other programmers or for future reference.
💡Key Conceptual Anchor:Introduction To Python
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which type of Programming does Python support?
Correct Answer: Option D — all of the mentioned
Detailed Academic Explanation:
Python supports all of the mentioned programming types. Python is a multi-paradigm programming language, which means it supports various programming styles, including object-oriented programming, structured programming, and functional programming. This versatility allows developers to choose the most appropriate paradigm for their specific needs and preferences. Python's support for multiple programming paradigms contributes to its flexibility and popularity among programmers for a wide range of applications.
💡Key Conceptual Anchor:Introduction To Python
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Is Python case sensitive when dealing with identifiers?
Correct Answer: Option B — yes
Detailed Academic Explanation:
Python is case sensitive when dealing with identifiers. Identifiers in Python, such as variable names, function names, and class names, are case-sensitive. This means that Python considers uppercase and lowercase letters as distinct characters. For example, variables "myVar" and "myvar" would be treated as two separate identifiers in Python. It's essential to maintain consistency in the casing of identifiers throughout the code to avoid errors related to undefined or misinterpreted identifiers.
💡Key Conceptual Anchor:Introduction To Python
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the correct extension of the Python file?
Correct Answer: Option C — .py
Detailed Academic Explanation:
The correct extension of a Python file is .py . Python files typically have the extension ".py", which indicates that they contain Python code. When you save a Python script, you should use the ".py" extension at the end of the file name to ensure that it's recognized as a Python file by the interpreter and text editors. Using the correct file extension also helps maintain organization and clarity in your project directory.
💡Key Conceptual Anchor:Introduction To Python
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is a variable defined in Python?
Correct Answer: Option C — x = 10
Detailed Academic Explanation:
In Python, a variable is defined by using the syntax x = 10 . To define a variable in Python, you simply write the variable name followed by an equal sign (=) and then the value you want to assign to that variable. This process binds the variable name to the specified value. Unlike some other programming languages, Python does not require explicit declaration of variable types. Instead, variables are dynamically typed based on the value assigned to them.
💡Key Conceptual Anchor:Introduction To Python
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Is Python code compiled or interpreted?
Correct Answer: Option A — Python code is both compiled and interpreted
Detailed Academic Explanation:
Python code is both compiled and interpreted . When you run a Python script, the source code is first compiled into bytecode by the Python interpreter. This bytecode is then executed by the Python Virtual Machine (PVM). Thus, Python combines elements of both compilation and interpretation. The compilation step translates the human-readable source code into bytecode, while the interpretation step executes the bytecode instructions. This hybrid approach allows Python to achieve a balance between performance and flexibility.
💡Key Conceptual Anchor:Introduction To Python
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
All keywords in Python are in . . . . . . . .
Correct Answer: Option B — lower case
Detailed Academic Explanation:
All keywords in Python are in lower case . Python's keywords, such as "if," "else," "for," "while," and others, are reserved words that have special meanings and purposes within the language. By convention, Python's keywords are all written in lowercase letters. This consistent style helps maintain readability and consistency across Python codebases
💡Key Conceptual Anchor:Introduction To Python
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following character is used to give single-line comments in Python?
Correct Answer: Option B — #
Detailed Academic Explanation:
In Python, the character used to give single-line comments is # . Any text that comes after the # symbol on a line is treated as a comment and is ignored by the Python interpreter during execution. Single-line comments are commonly used for adding explanations, notes, or reminders within the code to improve readability and understanding.
💡Key Conceptual Anchor:Introduction To Python
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a Python data type?
Correct Answer: Option C — Character
Detailed Academic Explanation:
In Python, Character is not a built-in data type. Python does not have a specific data type called "Character." Instead, individual characters are represented as strings of length one. Therefore, strings encompass both single characters and longer sequences of characters. The other options, Integer, Float, and String, are all valid data types in Python for representing integers, floating-point numbers, and sequences of characters, respectively.
💡Key Conceptual Anchor:Introduction To Python
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the main purpose of a loop in Python?
Correct Answer: Option C — To repeat a block of code
Detailed Academic Explanation:
The main purpose of a loop in Python is to repeat a block of code . Loops are fundamental control structures in programming languages that allow the execution of a certain block of code repeatedly. In Python, loops such as for loops and while loops enable you to iterate over sequences, perform operations on elements, and execute code multiple times based on specified conditions. This capability is essential for automating repetitive tasks, processing large amounts of data, and implementing algorithms that require repeated execution of certain steps.
💡Key Conceptual Anchor:Introduction To Python
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a valid loop in Python?
Correct Answer: Option B — until loop
Detailed Academic Explanation:
In Python, until loop is not a valid loop construct. Python does not have an "until" loop construct like some other programming languages such as Ruby or Perl. Instead, Python provides the while loop for executing a block of code repeatedly as long as a condition is true, and the for loop for iterating over a sequence of elements. Additionally, Python does not have a built-in "do-while" loop construct like some other languages, but similar behavior can be achieved using the while loop in combination with a pre-test.
💡Key Conceptual Anchor:Introduction To Python
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of a function in Python?
Correct Answer: Option C — To organize and reuse code
Detailed Academic Explanation:
The purpose of a function in Python is to organize and reuse code . Functions in Python encapsulate a set of instructions that perform a specific task. They allow you to break down your program into smaller, manageable pieces, making the code more organized, readable, and maintainable. By defining functions, you can avoid redundancy by reusing the same block of code multiple times throughout your program. This promotes code reusability and modularity, which are essential principles in software development. While Python supports arithmetic operations, graphical interfaces, and class definitions, these are not the primary purpose of functions.
💡Key Conceptual Anchor:Introduction To Python
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is a function defined in Python?
Correct Answer: Option B — def my_function():
Detailed Academic Explanation:
In Python, a function is defined using the syntax def my_function(): . The "def" keyword is used to indicate the start of a function definition, followed by the function name and parentheses. Any parameters that the function accepts are placed within these parentheses. The colon at the end of the line indicates the beginning of the function's code block. Inside the code block, you write the statements that define what the function does when called. This includes any operations, computations, or actions the function performs. Defining functions allows you to encapsulate reusable pieces of code and execute them whenever needed.
💡Key Conceptual Anchor:Introduction To Python
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to define a block of code in Python language?
Correct Answer: Option A — Indentation
Detailed Academic Explanation:
In Python language, a block of code is defined using Indentation . Indentation refers to the spaces or tabs that precede statements within a block of code. In Python, indentation is used to define the structure and hierarchy of code blocks, such as those within functions, loops, conditional statements, and classes. Proper indentation is crucial for Python's syntax and readability. Unlike some other programming languages that use braces or brackets to denote code blocks, Python relies solely on indentation to indicate the beginning and end of blocks. This consistent indentation style helps improve code readability and maintainability.
💡Key Conceptual Anchor:Introduction To Python
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used for function in Python language?
Correct Answer: Option B — def
Detailed Academic Explanation:
In Python language, the keyword used for defining a function is def . The "def" keyword is followed by the function name and a pair of parentheses that may contain parameters. This defines a function in Python. When you use the "def" keyword, you are indicating to Python that you are about to define a new function with the specified name and parameters. This keyword is essential for creating reusable blocks of code that can be called and executed multiple times throughout a program.
💡Key Conceptual Anchor:Introduction To Python
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the return statement do in a function?
Correct Answer: Option B — It outputs a value from the function
Detailed Academic Explanation:
In a function, the return statement is used to output a value from the function . When a return statement is encountered in a function, it immediately exits the function and sends back the specified value to the caller. This allows the function to produce a result or output that can be used in other parts of the program. The returned value can be assigned to variables, used in expressions, or passed as arguments to other functions. The return statement is essential for functions to be able to provide results or perform computations that yield outputs.
💡Key Conceptual Anchor:Introduction To Python
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of a module in Python?
Correct Answer: Option C — To organize functions, classes, and variables
Detailed Academic Explanation:
In Python, the purpose of a module is to organize functions, classes, and variables . A module in Python is a file containing Python definitions and statements. The primary purpose of modules is to organize related code into reusable units. Modules can contain functions, classes, variables, and even other modules. By structuring code into modules, you can break down large programs into smaller, more manageable pieces, making it easier to understand, maintain, and reuse. Additionally, modules facilitate code sharing and collaboration among developers by providing a standardized way to encapsulate and distribute functionality.
💡Key Conceptual Anchor:Introduction To Python
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is a valid way to handle errors in Python?
Correct Answer: Option B — Using the except clause
Detailed Academic Explanation:
In Python, a valid way to handle errors is using the except clause . The except clause is used in conjunction with try-except blocks to catch and handle exceptions or errors that occur during the execution of code. When an error occurs within the try block, Python looks for an appropriate except block to handle the error. If an except block corresponding to the type of error is found, the code within that block is executed to handle the error gracefully. This mechanism allows you to anticipate and respond to errors in your code, preventing unexpected crashes and improving the robustness of your programs.
💡Key Conceptual Anchor:Introduction To Python
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the try and except blocks in Python?
Correct Answer: Option A — To handle errors and exceptions
Detailed Academic Explanation:
In Python, the purpose of the try and except blocks is to handle errors and exceptions . The try block is used to enclose the code that may potentially raise an exception or error. The except block is used to specify the actions to be taken if an exception occurs within the try block. When an error occurs within the try block, Python jumps to the corresponding except block to handle the error gracefully, preventing the program from crashing. This mechanism allows you to anticipate and respond to errors in your code, improving its reliability and robustness.
💡Key Conceptual Anchor:Introduction To Python
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the role of the import statement in Python?
Correct Answer: Option C — To import external modules
Detailed Academic Explanation:
In Python, the import statement is used to import external modules . The import statement allows you to access functionality defined in external modules and use it in your Python program. Modules are Python files that contain Python code, including variables, functions, and classes. By importing modules, you can reuse code, organize related functionality, and extend the capabilities of your program. Python provides a rich ecosystem of built-in and third-party modules that cover a wide range of tasks and domains, including math, file I/O, networking, and more. The import statement is essential for leveraging this existing functionality and building powerful Python applications.
💡Key Conceptual Anchor:Introduction To Python
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of an if-statement in Python?
Correct Answer: Option D — To make decisions
Detailed Academic Explanation:
In Python, the purpose of an if-statement is to make decisions . The if-statement allows you to execute certain code blocks based on specified conditions. It evaluates a given expression and, if the result is true, executes the block of code associated with that condition. If the result is false, it may optionally execute an alternative block of code specified by an else statement. The ability to make decisions based on conditions is fundamental to programming, and the if-statement provides a powerful mechanism for controlling the flow of execution in a Python program based on varying circumstances.
💡Key Conceptual Anchor:Introduction To Python
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these is the definition for packages in Python?
Correct Answer: Option B — A folder of python modules
Detailed Academic Explanation:
In Python, packages are defined as a folder of python modules . A package in Python is a directory that contains a special file named "init.py" along with other Python modules or sub-packages. These modules can be accessed using dot notation. Packages allow you to organize related modules into a hierarchical structure, providing a convenient way to manage and distribute code. By structuring code into packages, you can create reusable components, improve code organization, and facilitate code sharing and collaboration.
💡Key Conceptual Anchor:Introduction To Python
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of print("Hello, " + "world!")?
Correct Answer: Option A — Hello, world!
Detailed Academic Explanation:
The output of print("Hello, " + "world!") is Hello, world! . The print() function in Python is used to output text to the console. In this case, the function prints the concatenated string "Hello, " followed by "world!" resulting in "Hello, world!" being displayed on the console. The plus (+) operator is used for string concatenation, which combines the two strings into a single string. Therefore, the correct output is "Hello, world!".
💡Key Conceptual Anchor:Introduction To Python
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the range() function in Python generate?
Correct Answer: Option A — A sequence of integers
Detailed Academic Explanation:
The range() function in Python generates a sequence of integers . When called with one argument, range(n) produces a sequence of integers from 0 up to (but not including) n. When called with two arguments, range(start, stop) produces a sequence of integers from start up to (but not including) stop. The range() function is commonly used in for loops to iterate over a sequence of numbers. It provides a convenient way to generate sequences of integers without needing to manually specify each individual value.
💡Key Conceptual Anchor:Introduction To Python
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the value of the following Python expression? 4 + 3 % 5
Correct Answer: Option A — 7
Detailed Academic Explanation:
The expression 4 + 3 % 5 evaluates to 7 in Python. Here's the breakdown: #1. 3 % 5 calculates the remainder when 3 is divided by 5, which is 3. #2. 4 + 3 then adds 4 to the result of the modulo operation, resulting in 7. Therefore, the value of the expression is 7.
💡Key Conceptual Anchor:Introduction To Python
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Python supports the creation of anonymous functions at runtime, using a construct called . . . . . . . .
Correct Answer: Option C — lambda
Detailed Academic Explanation:
In Python, the creation of anonymous functions at runtime is supported using a construct called lambda . The lambda keyword in Python is used to define anonymous functions, also known as lambda functions. Lambda functions are small, inline functions that can have any number of parameters but can only have one expression. They are often used for short, one-off operations where defining a named function would be overkill. Lambda functions are particularly useful when passing functions as arguments to higher-order functions like map(), filter(), and reduce().
Operators with higher precedence are evaluated before operators with lower precedence. When operators have the same precedence, they are evaluated from left to right. Therefore, the correct order of precedence in Python is Exponential, Parentheses, Division, Multiplication, Addition, Subtraction .
💡Key Conceptual Anchor:Introduction To Python
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does pip stand for python?
Correct Answer: Option C — Preferred Installer Program
Detailed Academic Explanation:
In Python, pip stands for Pip Installs Packages. Pip is a package management system used to install and manage software packages written in Python. It simplifies the process of installing and managing dependencies for Python projects. With pip, you can easily install, uninstall, and upgrade Python packages from the Python Package Index (PyPI) or other sources. It is a valuable tool for Python developers to streamline the development process and ensure that their projects have access to the necessary libraries and dependencies.
💡Key Conceptual Anchor:Introduction To Python
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is true for variable names in Python?
Correct Answer: Option B — unlimited length
Detailed Academic Explanation:
In Python, variable names have the following characteristics: They can be of unlimited length , allowing for descriptive and meaningful names. They can consist of letters (both uppercase and lowercase) , digits , and underscores (_) . They cannot begin with a digit . They are case-sensitive , meaning uppercase and lowercase letters are considered distinct. Therefore, the correct statement for variable names in Python is that they have unlimited length .
💡Key Conceptual Anchor:Introduction To Python
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following functions is a built-in function in python?
Correct Answer: Option B — print()
Detailed Academic Explanation:
In Python, the print() function is a built-in function . Built-in functions are functions that are available as part of the Python language and do not require any imports or external dependencies to use. They are pre-defined and readily accessible for common tasks such as input/output operations, mathematical calculations, type conversions, and more. The print() function, in particular, is widely used to display output to the console or other output streams. It takes one or more arguments and prints them to the standard output, separated by spaces by default. Therefore, the correct option for the built-in function in Python is print() .
💡Key Conceptual Anchor:Introduction To Python
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the use of id() function in python?
Correct Answer: Option B — Id returns the identity of the object
Detailed Academic Explanation:
In Python, the id() function is used to return the identity of an object . Every object in Python has a unique identity, which is a numeric value that is guaranteed to be unique and constant for the lifetime of the object. The id() function returns this unique identifier for the specified object. It can be used to determine whether two variables refer to the same object or not. Therefore, the correct usage of the id() function in Python is to return the identity of the object .
💡Key Conceptual Anchor:Introduction To Python
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is the use of function in python?
Correct Answer: Option C — Functions are reusable pieces of programs
Detailed Academic Explanation:
In Python, the primary use of functions is to create reusable pieces of programs . Functions allow you to encapsulate a block of code that performs a specific task and give it a name, making it reusable throughout your program. By defining functions, you can break down complex tasks into smaller, more manageable units, which improves modularity and maintainability of your code. Functions can be called multiple times from different parts of your program, allowing you to avoid code duplication and write more efficient and organized code. Therefore, the correct usage of functions in Python is that they are reusable pieces of programs .
💡Key Conceptual Anchor:Introduction To Python
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following functions can help us to find the version of python that we are currently working on?
Correct Answer: Option D — sys.version
Detailed Academic Explanation:
In Python, to find the version of Python that we are currently working on, we can use the sys.version attribute. The sys.version attribute returns a string containing the Python version number and additional information about the Python implementation. It does not require any arguments, so the correct way to access the version information is sys.version . Therefore, the correct option to find the version of Python is sys.version .
💡Key Conceptual Anchor:Introduction To Python
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python program? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)
Correct Answer: Option C — 0 1 2
Detailed Academic Explanation:
The code initializes the variable i to 0. Then, it enters a while loop that continues as long as i is less than 5. Inside the loop, it prints the current value of i . It then increments i by 1. If i becomes equal to 3, the if condition is met, and the break statement is executed, exiting the loop. Otherwise, the loop continues until i reaches 5. Since the loop is exited via the break statement and not by reaching the end condition, the else block associated with the loop is not executed. Therefore, the output will be: 0 1 2 .
💡Key Conceptual Anchor:Introduction To Python
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the order of namespaces in which Python looks for an identifier?
Correct Answer: Option B — Python first searches the built-in namespace, then the local namespace and finally the global namespace
Detailed Academic Explanation:
When Python encounters an identifier (variable or function name), it searches for it in a specific order across different namespaces. The order of namespaces that Python looks for an identifier is: Built-in namespace: Python first searches the built-in namespace, which contains the names of all built-in functions, exceptions, and constants. Local namespace: Next, Python searches the local namespace, which contains names defined within the current function or code block. Global namespace: If the identifier is not found in the local namespace, Python searches the global namespace, which contains names defined at the top level of the current module or in the global scope. If the identifier is not found in any of these namespaces, Python raises a NameError. Therefore, the correct order of namespaces in which Python looks for an identifier is: built-in namespace, local namespace, global namespace .
💡Key Conceptual Anchor:Introduction To Python
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.