Python Q&A - Unit 1, 2 & 3
Short Answer Questions (SAQs)
Unit 1
1. Briefly explain about Python programming.
Python is a high-level, interpreted programming language known for its
simplicity and readability. It is widely used in various fields like web
development, data science, AI, machine learning, and cybersecurity.
2. Explain the Structure of a Python program.
A Python program follows this structure:
• Header: Importing modules (e.g., import math)
• Comments: Used for documentation (e.g., # This is a comment)
• Functions: User-defined reusable code blocks (def
function_name():)
• Main Code: The actual execution logic
3. Write short notes on Input and Output Statements.
Input: Used to take user input.
name = input("Enter your name: ")
print("Hello,", name)
Output: Used to display results.
print("Welcome to Python")
4. Write short notes on Python numbers.
Python supports three types of numbers:
• Integers (int): Whole numbers (e.g., 10, -5)
• Floating Point (float): Decimal numbers (e.g., 3.14, -0.99)
• Complex Numbers (complex): Numbers with imaginary parts (e.g., 2 +
3j)
5. Discuss about Python Literals.
Literals are constant values assigned to variables:
• Numeric Literals: 10, 3.14
• String Literals: "Hello", 'Python'
• Boolean Literals: True, False
• None Literal: Represents the absence of value (None)
6. Explain Comments in Python programming.
Comments help in understanding the code:
• Single-line Comment: # This is a comment
• Multi-line Comment:
'''
This is a multi-line comment.
Used for documentation.
'''
Long Answer Questions (LAQs)
Unit 1
1. What is Python Programming? Explain the features of
Python Programming.
Python is a powerful, easy-to-learn, and highly versatile programming
language. It is widely used in AI, web development, automation, and
cybersecurity.
Features of Python:
• Easy to Learn & Readable: English-like syntax.
• Dynamically Typed: No need to declare variable types.
• Interpreted: Executes code line-by-line.
• Extensive Libraries: Includes NumPy, Pandas, etc.
• Object-Oriented & Functional: Supports both programming paradigms.
2. Give the Steps for Installing Python.
Steps to install Python:
• Download Python from python.org
• Install Python and check "Add Python to PATH"
• Verify installation using:
python --version
3. Briefly explain about Strings in Python programming.
Strings are sequences of characters enclosed in single or double quotes.
String operations: Concatenation (+), Repetition (*), Slicing ([:])
s = "Hello, Python!"
print(s.upper())
4. Define Operators and explain any five Operators with syntax
and examples.
Operator Type Example
Arithmetic +, -, *, /, //, %
Comparison ==, !=, >, <
Logical and, or, not
Membership in, not in
Identity is, is not
Unit 2
1. Explain Conditional statements in Python.
if x > 5:
print("Greater")
elif x == 5:
print("Equal")
else:
print("Smaller")
2. Explain Looping statements in Python.
for i in range(5):
print(i)
3. Define Functions. Explain Built-in functions with syntax and
examples.
Python has built-in functions like print(), len(), type()...
4. What is a Function? Explain User-defined functions in
Python.
def add(a, b):
return a + b