0% found this document useful (0 votes)
10 views3 pages

Python DjangoA

Uploaded by

nitinolxuser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Python DjangoA

Uploaded by

nitinolxuser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

40. Explain the use of “with” statement.

Ans. In Python, generally “with” statement is used to open a file, process the data present in the
file, and also to close the file without calling a close() method. “with” statement makes the
exception handling simpler by providing cleanup activities.

General form of with:

with open(“filename”, “mode”) as file-var:

processing statements

41. How can we display the contents of text file in reverse order?

Ans. (a) Convert the given file into a list.

(b) Reverse the list by using reversed()

(c) Eg: for line in reversed(list(open(“file-name”,”r”)))

(d) print(line)

42. Differentiate between append() and extend() methods.

Ans. Both append() and extend() methods are methods of list. These methods are used to add
elements at the end of the list.

• append(element) – adds the given element at the end of the list which has called this method.

• extend(another-list) – adds the elements of another list at the end of the list which is called the
extend method.

43. What are the advantages of Python recursion?

Ans. Implementing something using Python recursion requires less effort. The code we write using
recursion will be comparatively smaller than the code that is implemented by loops. Again, codes
that are written using recursion are easier to understand also.

44. What do you understand by Python modules?

Ans. A file containing Python definitions and statements is called a Python module. So naturally,
the filename is the module name which is appended with the suffix .py.

45. What do you understand by Python package?

Ans. Python package is a collection of modules in directories that gives a package hierarchy. More
elaborately, Python packages are a way of structuring Python’s module by using “dotted module
names”. So A.B actually indicates that B is a sub-module which is under a package named A.

46. How can we get current directory using Python?

Ans. To get current directory in Python, we need to use os module. Then, we can get the location
of the current directory by using getcwd() function.

47. What is the difference between del keyword and clear() function?

Ans. The difference between del keyword and clear() function is that while del keyword removes
one element at a time, clear function removes all the elements.
48. What is primary key?

Ans. Primary key is a combination of columns that uniquely identifies a row in a relational table.

49. What is candidate key?

Ans. All possible combinations of columns that can possibly serve as the primary key are called
candidate keys.

50. What is foreign key?

Ans. A combination of columns where values are derived from primary key of some other table is
called the foreign key of the table in which it is contained.

51. What is alternate key?

Ans. A candidate key that is not serving as a primary key is called an alternate key.

52. What is MYSQL?

Ans. MYSQL is an open source RDBMS that relies on SQL for processing the data in the database.
The database is available for free under the terms of General Public License (GPL).

53. What is RDBMS?

Ans. Relational Database Management System (RDBMS) facilitates access, security and integrity of
data and eliminates data redundancy. For example, MYSQL, Oracle, Microsoft Sql Server, etc.

54. What is the use of drop command?

Ans. Drop command is used to delete tables. For example, Drop Table Orders. Delete commands
are used to delete rows of a table.

55. What do you understand by NOT NULL constraint?

Ans. This constraint ensures that the null values are not permitted on a specified column. This
constraint can be defined at the column level and not at the table level.

56. What is the significance of COUNT?

Ans. It is used to count the number of values in a given column or number of rows in a table. For
example, Select count (Roll No.) from students.

57. How can we delete a table in MYSQL?

Ans. We can delete a table in MYSQL using the drop command.

58. How can we delete a record in MYSQL?

Ans. We can delete a record in MYSQL using the delete command.

59. How can we add a record and add a column in a table?

Ans. We can add a record by using insert command and we can add a column through the alter
table command.

60. Give any two differences between GET and POST submission methods of HTML form.

Ans.
GET Method POST Method

All form data is encoded into the URL Form data appears within the message body of
appended to the action URL as query string the HTTP request.
parameters.

Parameters remain in browser history, hence Parameters are not saved in browser history,
cannot be used to send password- like hence can be used to send sensitive
sensitive information. information.

Can be bookmarked. Cannot be bookmarked.

Easier to hack for script kiddies. More difficult to hack.

Can be cached. Cannot be cached.

You might also like