• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

PYTHON Interview Questions Answers

Question - 41 : - Normal 0 false false false EN-US X-NONE X-NONE

Answer - 41 : - Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 First list are mutable while tuples are not, and second tuples can be hashed e.g. to be used as keys for dictionaries. As an example of their usage, tuples are used when the order of the elements in the sequence matters e.g. a geographic coordinates, "list" of points in a path or route, or set of actions that should be executed in specific order. Don't forget that you can use them a dictionary keys. For everything else use lists. /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

Question - 42 : - What is the difference between tuples and lists in Python?

Answer - 42 : - The main differences between lists and tuples are − Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.

Question - 43 : - What is the output of print str * 2 if str = 'Hello World!'?

Answer - 43 : - It will print string two times. Output would be Hello World!Hello World!.

Question - 44 : - What is the output of print str if str = 'Hello World!'?

Answer - 44 : - It will print complete string. Output would be Hello World!.

Question - 45 : - What is the output of print str[0] if str = 'Hello World!'?

Answer - 45 : - It will print first character of the string. Output would be H.

Question - 46 : - What is the output of print list[0] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

Answer - 46 : - It will print first element of the list. Output would be abcd.

Question - 47 : - What is the output of print list if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

Answer - 47 : - It will print complete list. Output would be ['abcd', 786, 2.23, 'john', 70.200000000000003].

Question - 48 : - How will you compare two lists?

Answer - 48 : - cmp(list1, list2) − Compares elements of both lists.

Question - 49 : - What is the purpose of is operator?

Answer - 49 : - is − Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here is results in 1 if id(x) equals id(y).

Question - 50 : - What is the purpose of PYTHONHOME environment variable?

Answer - 50 : - PYTHONHOME − It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners