1. Write down difference between set and dictionary in python?
Ans: A. Set:
• A set is an unordered collection of unique elements.
• Elements in a set cannot be duplicated.
• It is defined using curly braces {} or the set() constructor.
• Sets are mutable but do not support indexing.
B. Dictionary:
• A dictionary is a collection of key-value pairs.
• Keys in a dictionary are unique, while values can be duplicated.
• It is also defined using curly braces {} with key-value pairs separated by colons.
2. Define numpy.
Ans: NumPy is a popular Python library used for numerical computing. It provides support
for large, multi-dimensional arrays and matrices, along with a collection of mathematical
functions to perform operations on these arrays efficiently. It is widely used in data
science, machine learning, and scientific computing.
4. Explain features of python
Ans: Features of Python:
• Easy to Learn and Use: Python has a simple syntax and is easy for beginners to
learn.
• Interpreted Language: Python code is executed line by line, making debugging easier.
• Dynamically Typed: Variable types are inferred at runtime, so you don't need to
declare them.
• Object-Oriented: Supports classes and objects, facilitating code reusability.
• Extensive Libraries: Python has a vast collection of libraries and frameworks
6. Define Tkinter.
Ans: Tkinter is the standard GUI (Graphical User Interface) library in Python. It provides
tools to create windows, buttons, labels, text fields, and other GUI elements. Tkinter is built
on top
12. Difference between Python list and Numpy array.
Ans: Difference between Python List and NumPy Array:
• Python List:
o Can store heterogeneous elements (e.g., integers, strings, floats).
o Slow for numerical operations because it lacks efficient vectorized
operations.
• NumPy Array:
o Homogeneous, stores elements of the same data type (usually numerical).
o Faster for mathematical operations due to efficient memory usage and
17. What is Sea born?
Ans: Seaborn is a Python data visualization library built on top of Matplotlib. It provides a
high-level interface for creating attractive and informative statistical graphics, particularly
for working with pandas data frames. t for vectorized operations.
18. Write any two common exceptions in Python.
Ans:• ValueError: Raised when a function receives an argument of the correct type but an
inappropriate value.
• TypeError: Raised when an operation or function is applied to an object of an
inappropriate type.
31. What are the properties of a Dictionary?
Ans: 1. Unordered: Dictionaries are unordered collections of key-value pairs.
2. Keys Are Unique: Keys must be unique, but values can be duplicated.
3. Mutable: You can change, add, or remove key-value pairs after the dictionary is
created.
j)State the uses of TensorFlow.
Ans:Uses of TensorFlow: -Building and training machine learning models.
-Deep learning applications including neural networks.
-Deployment of mode ls in production environments
17. Explain features of pandas in Python.
Ans: Pandas is a powerful data manipulation and analysis library for Python, widely used in
data science. Some of its key features are:
1. DataFrame: The primary data structure, similar to a table with rows and columns,
ideal for handling and analyzing structured data.
2. Data Alignment: Pandas automatically aligns data in computations based on labels,
making it easy to manipulate missing or irregular data.
3. Handling Missing Data: Pandas provides functions like isnull(), fillna(), and dropna()
to identify and handle missing data efficiently.
4. Indexing and Slicing: Powerful methods for selecting, filtering, and slicing data using
labels, booleans, or positions.
22. Explain function Arguments in detail?
Ans: In Python, function arguments allow you to pass values to a function when you call it.
There are several types of function arguments:
1. Positional Arguments: These are arguments that need to be passed in the same
order as the function definition.
def greet(name, age)
2. Keyword Arguments: Arguments can be passed using their parameter names,
allowing them to be provided in any order.
3. Default Arguments: You can provide default values for function parameters. If no
argument is passed for that parameter, the default value will be used.
def greet(name, age=30):
4. Variable-Length Arguments: There are two types of variable-length arguments:
o (Non-keyword arguments): Allows passing a variable number of positional
arguments.
o (Keyword arguments): Allows passing a variable number of keyword
arguments.
29. Explain the features of Numpy
Ans: NumPy (Numerical Python) is a fundamental package for numerical computing in
Python. It provides support for large multi-dimensional arrays and matrices, along with a
collection of mathematical functions to operate on these arrays efficiently.
Key Features:
1. N-Dimensional Array: The core feature of NumPy is a powerful array object that supports
n-dimensional arrays.
2. Broadcasting: NumPy allows for element-wise operations on arrays of different
shapes, through broadcasting.
3. Mathematical Functions: NumPy provides a wide variety of functions for
mathematical operations, such as linear algebra, random number generation.
4. Array Slicing and Indexing: NumPy allows efficient slicing and indexing of arrays,
enabling selection and manipulation of array subsets.
4. Raise statement
Ans: The raise statement is used to trigger an exception in Python. You can use it to raise
built-in exceptions or your custom exceptions. Raising exceptions is useful for enforcing
certain conditions in your code.
5. Package
Ans: In Python, a package is a way of organizing related modules into a single directory
hierarchy. A package typically contains an __init__.py file that defines the package's
interface and can also include sub-packages and modules. Packages help in organizing
code and preventing naming conflicts.
7. Tuple
Ans: A tuple is an immutable sequence type in Python, which means that once a tuple is
created, its contents cannot be changed. Tuples can hold a collection of items, and they
are defined using parentheses ().
d)What is the use of random () in random module?
Ans:-The random()function in the random module generates a random floating-point number
between0.0to1.0.import random
i)What are advantages of Pandas?
Ans:Advantages of Pandas:
-Easy data manipulation and analysis.
-Data structures like Series and Data Frame for handling structured data.
-Powerful data alignment and indexing capabilities
e) List out Geometry management methods.
Ans:1. pack(): Packs widgets into a block before placing them in the parent widget.
2. grid(): Organizes widgets in a table-like structure.
3. place(): Places widgets at an absolute position you specify.
h) Write any two common exceptions in Python.
Ans:1Value Error: Raised when a function receives an argument of the right
type but inappropriate value.
2. Index Error: Raised when trying to access an index that is out of range for a list or tuple.
d) What is inheritance? Write its benefits and syntax.
Ans:
Inheritance is a feature of object-oriented programming that allows a class (child class) to inherit
attributes and methods from another class (parent class). This promotes code reusability and
establishes a hierarchical relationship.
Benefits:1. Code Reusability: Avoids code duplication.
2. Extensibility: Allows extending existing classes with new functionality.
3. Polymorphism: Enables method overriding
19. Write Python GUI program to create back ground with changing colors.
Ans:
import tkinter as tk
import random
def change_color():
colors = ["red", "green", "blue", "yellow", "pink", "orange"]
root.config(bg=random.choice(colors))
root = tk.Tk()
root.title("Color Changer")
root.geometry("300x300")
button = tk.Button(root, text="Change Background Color", command=change_color)
button.pack(pady=50)
8. Write a Python program to swap the value of two variables.
Ans:
a=5
b = 10
a, b = b, a
print("a =", a, "b =", b) # a = 10, b = 5
18. Write an anonymous function to find area of rectangle.
Ans:
area = lambda length, width: length * width
print("Area of Rectangle:", area(5, 10))
9.Write a python script using class to reverse a string word by word?
Ans:
class String Reverser:
def__init__(self, string):
self.string=string
def reverse_words(self):
words=self.string.split()
reversed_words=' '.join(reversed(words))
return reversed_words
reverser=String Reverser("HelloWorld")
print(reverser.reverse_words())
10. List out Geometry management methods.
Ans:
1. pack(): Packs widgets into a block before placing them in the parent widget.
2. grid(): Organizes widgets in a table-like structure.
3. place(): Places widgets at an absolute position you specify.
11.list out any 5 buttons option in python.
Bg, command, fg, font. They are the buttons