Python QB ans
Python QB ans
Q2
ANS:
key features of Python:
1. Easy to Learn & Use – Python has a simple syntax similar to English, making it beginner-friendly.
2. Interpreted Language – Python executes code line by line, making debugging easier.
3. Object-Oriented & Procedural – Supports both programming paradigms for flexibility.
4. Extensive Libraries – Provides built-in modules for tasks like data handling, web development, and AI.
5. Platform-Independent – Runs on multiple operating systems like Windows, Mac, and Linux without modification.
Q3
ANS:
Applications of Python:
1. Web Development: Django, Flask, FastAPI
2. Data Science & Analytics: Pandas, NumPy, Matplotlib
3. Machine Learning & AI: TensorFlow, Scikit-learn, PyTorch
4. Automation & Scripting: Selenium, PyAutoGUI
5. Game Development: Pygame, Panda3D
Q4
ANS:
-indentation is crucial as it defines the structure of the code and determines how statements are grouped.
-Unlike other languages that use braces {}, Python relies on indentation to indicate blocks of code.
Q5
ANS:
-An operator in Python is a symbol that performs an operation on values or variables.
-Operators are used in mathematical calculations, comparisons, and logical expressions.
Q7
ANS:
-A dictionary in Python is a built-in data structure that stores data as key-value pairs.
-Each item in a dictionary consists of a key and a corresponding value.
-The key acts as an identifier for the value, and you can use it to access the value efficiently.
-Dictionaries in Python are mutable, meaning that you can modify them by adding, updating, or removing key-value pairs.
-To create a dictionary, you use curly braces {} with key-value pairs separated by colons :.
-For example, {'name': 'Alice', 'age': 30} is a dictionary with two key-value pairs.
-Keys must be unique within a dictionary, and they are typically strings, numbers, or tuples.
-Values, on the other hand, can be of any data type.
Q8
ANS:
-A variable in programming is a name that refers to a memory location where data can be stored.
-It acts as a container for holding values or data types (such as integers, strings, floats, etc.) that can be used and
manipulated throughout a program.
-In Python, variables do not require explicit type declarations, as Python automatically determines the type of a variable
based on the assigned value.
-Rules for Declaring Variables in Python:
1.Variables in python can be created from alphanumeric character and underscore(_)character.
2.A variable cannot begin with a number.
3.The variable are case sensative.
4.Variable name should not be reserved word or keyword.
5.No special characteres are used execpt underscore(_) in variable declarartion.
6.Variable can be of unlimited length
-Eg.,
>>> a = 10
>>> print(a)
10
Q9
ANS:
r = float(input("Enter radius: "))
h = float(input("Enter height: "))
pi = 3.1416 # Approximate value of π
volume = pi * r * r * h
surface_area = 2 * pi * r * (r + h)
print("Volume:", volume)
print("Surface Area:", surface_area)
Q10
ANS:
Built-in Functions in Python:
-Python provides built-in functions that are readily available for use without needing to import any modules.
-These functions help perform common tasks like mathematical operations, input/output handling, type conversions, and
more.
6. Utility Functions
- id(x) – Returns the memory address of x.
- help(x) – Displays help information about x.
- range(start, stop, step) – Generates a sequence of numbers.