Avatto>>DATA SCIENTIST>>SHORT QUESTIONS>>Python Interview Questions
To retrieve data from a database we have to make use of the module available for that database. For MySQL database, we import MySQLdb module in our Python script.
We have to first connect to a specific database by passing URL, username, password and the name of database.
Once we establish the connection, we can open a cursor with cursor() function. On an open cursor, we can run fetch() function to execute queries and retrieve data from the database tables.
pet_name = {'Nitin':['Kamal','Chintu'],
'Richa':['Shankar','Megha']}
for name,pet in pet_name.items():
print(name)
for x in pet:
print('-',x)
import matplotlib.pyplot as plt
a = ['Apple','Mango','Pineapple']
b = [40,60,50]
plt.bar(a,b)
labels = 'Sachin','Dhoni','Kohli','Dravid'
size = [100,25,70,50]
colors = ['pink','blue','red','orange']
explode = (0.1,0,0,0)
plt.pie(size,explode=explode,labels=labels,colors=colors,autopct='%1.1f%%',shadow=True,startangle=140)
plt.axis('equal')
plt.show()


Description