2. Which special character is used for a new line? Answer: \n 3. Python commands are evaluated/executed in _______. Answer: Interpreter 4. The symbol used for a single-line comment in Python. Answer: # (hash symbol) 5. Python statement that forces a specified exception to occur. Answer: raise 6. ELSE keyword is used in exception handling in Python (True/False). Answer: True 7. ______ exception catches all exceptions in Python. Answer: BaseException 8. Partition and exchange sort is _______. Answer: Quick Sort 9. Knapsack problem is also known as ______ problem. Answer: 0/1 Problem 10. The method to display the graphical window on the computer screen. Answer: show() 11. Default file extension for storing PyLab Figure is _______. Answer: .fig 12. The function to save a plot graph to a file in Python. Answer: savefig() 13. URL stands for ______. Answer: Uniform Resource Locator 14. UDP stands for ______. Answer: User Datagram Protocol 15. TCL stands for ______. Answer: Tool Command Language 16. TCP/IP stands for _______. Answer: Transmission Control Protocol/Internet Protocol 17. SQL stands for _______. Answer: Structured Query Language 18. Which package is used to connect a MySQL database in Python? Answer: mysql-connector-python 19. List out the parameters of the connection() function. Answer: host, user, password, database 20. Which method of the cursor class fetches only one row from the table? Answer: fetchone() 21. IDLE stands for _______. Answer: Integrated Development and Learning Environment 22. The symbol used as a shell prompt in Python. Answer: >>> (three greater-than signs) 23. The method to read a string from an open file in Python. Answer: read() 24. ADT stands for ________. Answer: Abstract Data Type 25. Brief description about the class is given by _______. Answer: docstring 26. The error raised when division or modulo by zero occurs. Answer: ZeroDivisionError 27. PyLab is embedded with the ______ module of Python. Answer: Matplotlib 28. Give the full form of PNG. Answer: Portable Network Graphics 29. Dynamic programming is an optimization over plain _______. Answer: Recursion 30. The function used to display a chart/figure in Python. Answer: show() 31. JSON stands for _______. Answer: JavaScript Object Notation 32. CSV stands for _______. Answer: Comma-Separated Values 33. RegEx stands for _______. Answer: Regular Expression 34. If there is no match, _______ will be returned instead of the Match object. Answer: None 35. ROC stands for __________. Answer: Receiver Operating Characteristic 36. MAE stands for ______. Answer: Mean Absolute Error 37. AUC stands for ______. Answer: Area Under the Curve 38. MSE stands for ______. Answer: Mean Squared Error 39. The function used to save plots to files in Python is _______. Answer: savefig() 40. The symbol used for multi-line comments in Python is _______. Answer: ''' (triple single quotes) or """ (triple double quotes) 41. IDLE stands for _______. Answer: Integrated Development and Learning Environment 42. ______ is the inventor of Python. Answer: Guido van Rossum 43. Default extension of a Python file is _______. Answer: .py 44. ______ is a container for storing basic data values. Answer: Variable 45. ADT stands for _______. Answer: Abstract Data Type 46. ______ statement forces an exception to occur. Answer: raise 47. ______ catches all exceptions. Answer: BaseException 48. ______ block executes code, whether an exception occurs or not. Answer: finally 49. ______ function is used to create a new figure. Answer: figure() 50. ______ function is used to display a plot. Answer: show() 51. ______ function is used to save a plot file. Answer: savefig() 52. An example of a sorting algorithm that uses the divide- and-conquer approach is ______ sort. Answer: Quick Sort 53. The ______ module is commonly used for socket programming to handle network connection. Answer: socket 54. The ______ method is used to associate the socket with a specific network interface and port number. Answer: bind() 55. The ______ protocol is used to send email over the internet. Answer: SMTP (Simple Mail Transfer Protocol) 56. The "socket.gethostname()" function in Python returns the ______ of the machine. Answer: Hostname 57. ______ method is used to call existing procedures of MySQL database. Answer: callproc() 58. ______ method gives information about the last query. Answer: info() 59. ______ method accepts a MySQL query as a parameter and executes the given query. Answer: execute() 60. ______ method fetches the next row in the result of a query and returns it as a tuple. Answer: fetchone()
1) Explain tuple with an example.
Answer: A tuple is an immutable sequence in Python, used to store multiple items in a single variable. Tuples are created using parentheses, e.g., my_tuple = (1, 2, 3). Tuples cannot be modified after creation, making them useful for storing constant values. 2) What is a global variable? Answer: A global variable is one that is defined outside any function and can be accessed in any function within the code. It is declared in the global scope, so functions can read or modify it using the global keyword if needed. 3) Explain assertions in Python. Answer: Assertions are debugging aids that check if a condition is True. If not, Python raises an AssertionError. They are used for sanity checks and are written using assert, e.g., assert x > 0, "x should be positive". 4) What is a class in Python? Answer: A class in Python is a blueprint for creating objects, encapsulating data (attributes) and functions (methods). Classes are defined using the class keyword, e.g., class Car: which then can be instantiated as objects. 5) Explain the show() function in Python. Answer: The show() function in libraries like Matplotlib displays a graphical plot or chart on the screen. After plotting data, calling show() renders the plot. 6) Explain the legend() function in Python. Answer: In Matplotlib, legend() adds a legend to the plot, which is a small box describing elements of the chart. Labels are automatically assigned if specified in plot(). 7) Write code to download an image from the internet in Python.
8) Explain the Button widget with an example.
Answer: The Button widget in Tkinter is used to create clickable buttons in a GUI application 9) Write a Python code to insert a record in a table. Answer:
a)
10) Write a Python code to delete a record from a table.
Answer:
a)
11) Explain recursion in Python.
Answer: Recursion is a function calling itself to solve a problem in smaller parts. For instance, calculating factorial using def factorial(n): return 1 if n == 0 else n * factorial(n-1). 12) Explain tuple with an example. Answer: Tuples are immutable collections of items, e.g., example_tuple = ('apple', 'banana'). They are used to store data that should not be changed. 13) What is the self keyword in Python? Explain with an example. Answer: self represents the instance of the class in Python, allowing access to attributes and methods of the class. Example:
14) Explain binary search with an example.
Answer: Binary search is an efficient algorithm for finding a target value in a sorted list by repeatedly dividing the search range in half. Example:
15) Explain the figure() function in Python.
Answer: figure() in Matplotlib creates a new figure window for plotting. It allows customization like figure size and title before plotting. 16) Explain the plot() function in Python. Answer: plot() in Matplotlib is used to plot lines and data points. It accepts x and y values, and styles, e.g., plot(x, y, 'g- '). 17) Explain the difference between search() and findall() in Python. Answer: In re module, search() finds the first match in a string, while findall() returns all matches as a list. 18) List out all flags modifiers with a single-line meaning. Answer:
a) re.IGNORECASE: Ignores case
b) re.MULTILINE: Matches start/end in multiple lines
c) re.DOTALL: Allows . to match newline
19) Explain the head() function in Python.
Answer: In pandas, head() returns the first five rows of a DataFrame, allowing a quick view of the data. 20) Explain the tail() function in Python. Answer: In pandas, tail() returns the last five rows of a DataFrame for quick review of the dataset's end. 21) Explain TUPLE with example. Answer: Tuples store multiple items in one variable. Example: example_tuple = (1, 2, 'apple'). 22) Explain LIST data type. Answer: Lists are mutable sequences in Python, used to store multiple items. Defined using square brackets, e.g., my_list = [1, 2, 3]. 23) Explain AttributeError. Answer: AttributeError occurs when an attribute reference or assignment fails, typically due to a missing attribute in an object. 24) Explain ValueError. Answer: ValueError occurs when an operation receives an argument of correct type but inappropriate value, e.g., int("abc"). 25) Explain pylab.title, xlabel and ylabel. Answer: In Matplotlib:
a) title(): Adds title to the plot.
b) xlabel(): Labels x-axis.
c) ylabel(): Labels y-axis.
26) What is Memoization?
Answer: Memoization is an optimization technique where function results are cached for reuse, reducing repeated computations. 27) Explain socket.bind(). Answer: socket.bind() associates the socket with a specific IP and port, essential for servers to receive connections.
28) Explain socket.connect().
Answer: socket.connect() establishes a connection to a server socket, specifying the server's IP address and port. 29) Explain lastrowid in a statement. Answer: lastrowid retrieves the ID of the last inserted row in a database, useful for referencing newly added entries.
30) Explain column_names and description.
Answer: In MySQL, column_names lists all column headers in a table, while description provides metadata like column names and types.
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More