Python - 2 Marks Solution of Previous PUT - Bharat - Agg
Python - 2 Marks Solution of Previous PUT - Bharat - Agg
Example:
original = [1, 2, 3]
clone1 = original[: ] # Using slicing
clone2= list (or iginal) # Using list()
clone3 = original.copy( ) # Using copy()
print (clone1, clone2, clone3 )
Example:
string = "Python!"
# Traversing using a for loop
for char in string:
print ( char )
Differences:
Example:
Differences:
Example:
#r+mode
with open(' example.txt', 'r+')as file:
content = file .read()
file .write('Addit ional content')
# w+ mode
with open('example.txt', 'w+') as file:
file .write('New content ' ) # Overwrites
existing content
I. What do you mean by pandas in Python?
Pandas is a powerful library used for data analysis and
manipulation. It provides data structures like Series
and DataFrame for handling tabular data.
Features:
Example:
import pandas as pd
data = {'Name': ['Alice', 'Bob' ], 'Age': [25,
30]}
df = pd. DataFrame (data)
print(df)
Example:
import numpyas np
array = np.array(I[[1, 2], [3, 41], [[5, 6], [7,
81]]) # 2x2x2 array
print(array)