

{"id":10027,"date":"2018-03-07T05:33:40","date_gmt":"2018-03-07T05:33:40","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=10027"},"modified":"2020-01-23T10:01:54","modified_gmt":"2020-01-23T04:31:54","slug":"top-python-interview-questions-answer","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/","title":{"rendered":"150+ Python Interview Questions and Answers for Freshers [Latest]"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1379,&quot;href&quot;:&quot;https:\\\/\\\/www.python.org\\\/about\\\/gettingstarted&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251206211720\\\/https:\\\/\\\/www.python.org\\\/about\\\/gettingstarted\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 05:59:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-12 14:23:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-15 14:47:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-18 15:58:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-22 06:19:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-26 11:50:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-30 14:27:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-02 16:02:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-07 02:57:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 01:34:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 15:35:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-19 04:12:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-22 05:11:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-25 23:31:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-30 06:45:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-02 08:51:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-07 06:25:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 16:26:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 18:58:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 13:30:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 15:40:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 18:13:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 08:53:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 05:53:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 06:52:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 12:51:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 18:37:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 07:40:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:07:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 19:41:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 15:19:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 21:00:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-07 04:00:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 09:44:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 04:25:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 18:46:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 14:41:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-24 15:21:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-29 07:27:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-02 13:42:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-09 04:11:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-12 06:51:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-17 17:30:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-21 00:46:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-25 01:39:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-28 05:23:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 00:36:51&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-06 13:57:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-10 13:58:08&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-10 13:58:08&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:2014,&quot;href&quot;:&quot;https:\\\/\\\/data-flai&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>DataFlair is devoted to help Python learners become successful in their Python careers. That&#8217;s why we are publishing an interesting and helpful series of Python Interview Questions and Answers. In this series, you will get 150+ Python Interview Questions and Answers in 3 different parts, that covers<\/p>\n<ul>\n<li><strong>Python Interview Questions and Answers for Beginners<\/strong><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-interview-questions\/\"><strong>Python Interview Questions and Answers for Intermediates<\/strong><\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-programming-interview-questions\/\"><strong>Python Interview Questions and Answers for Experienced<\/strong><\/a><\/li>\n<\/ul>\n<p>Starting with our first part that is Python Interview Questions and Answers for freshers. I have divided this blog into different categories.<\/p>\n<ul>\n<li>Common Python Interview Questions and Answers<\/li>\n<li>Frequently asked Python Interview Questions and Answers<\/li>\n<li>Basic Python Programming Interview Questions and Answers<\/li>\n<li>Top Python Interview Questions and Answers<\/li>\n<li>Technical Python Interview Questions and Answers<\/li>\n<li>Python OOPS Interview Questions and Answers<\/li>\n<li>Open-ended Python Interview Questions for Beginners<\/li>\n<\/ul>\n<h3>Common Python Interview Questions and Answers<\/h3>\n<p>The reason I am sharing these interview questions is that you can revise all your basic concepts. As you are a beginner, the interviewer will surely check your understanding of Python Fundamentals. Let&#8217;s start exploring the basic Python Interview Questions and Answers &#8211;<\/p>\n<p><strong>Q.1. What are the key features of Python?<\/strong><\/p>\n<p>If it makes for an introductory language to programming, Python must mean something. These are its qualities:<\/p>\n<ul>\n<li>Interpreted<\/li>\n<li>Dynamically-typed<\/li>\n<li>Object-oriented<\/li>\n<li>Concise and simple<\/li>\n<li>Free<\/li>\n<li>Has a large community<\/li>\n<\/ul>\n<p><strong>Q.2. Differentiate between lists and tuples.<\/strong><\/p>\n<p>The major difference is that a list is mutable, but a tuple is immutable. Examples:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; mylist=[1,3,3]\r\n&gt;&gt;&gt; mylist[1]=2\r\n&gt;&gt;&gt; mytuple=(1,3,3)\r\n&gt;&gt;&gt; mytuple[1]=2\r\n<\/pre>\n<p><strong>Traceback (most recent call last):<\/strong><\/p>\n<p><strong>File \u201c&lt;pyshell#97&gt;\u201d, line 1, in &lt;module&gt;<\/strong><\/p>\n<p><strong>mytuple[1]=2<\/strong><\/p>\n<p><strong>TypeError: \u2018tuple\u2019 object does not support item assignment<\/strong><\/p>\n<p><em><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-tuples-vs-lists\/\">Python Tuples vs Lists<\/a> &#8211; A Detailed Comparison<\/strong><\/em><\/p>\n<p><strong>Q.3. Explain the ternary operator in Python.<\/strong><\/p>\n<p>Unlike C++, we don\u2019t have ?: in Python, but we have this:<\/p>\n<p style=\"text-align: center\">[on true] if [expression] else [on false]<\/p>\n<p>If the expression is True, the statement under [on true] is executed. Else, that under [on false] is executed.<\/p>\n<p>Below is how you would use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a,b=2,3\r\n&gt;&gt;&gt; min=a if a&lt;b else b\r\n&gt;&gt;&gt; min<\/pre>\n<p><strong>2<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(\"Hi\") if a&lt;b else print(\"Bye\")<\/pre>\n<p><strong>Hi<\/strong><\/p>\n<p><strong>Q.4. What are negative indices?<\/strong><\/p>\n<p>Let\u2019s take a list for this.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; mylist=[0,1,2,3,4,5,6,7,8]<\/pre>\n<p>A negative index, unlike a positive one, begins searching from the right.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; mylist[-3]<\/pre>\n<p><strong>6<\/strong><\/p>\n<p>This also helps with slicing from the back:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; mylist[-6:-1]<\/pre>\n<p><strong>[3, 4, 5, 6, 7]<\/strong><\/p>\n<p><strong>Q.5. Is Python case-sensitive?<\/strong><\/p>\n<p>A language is case-sensitive if it distinguishes between identifiers like myname and Myname. In other words, it cares about case- lowercase or uppercase. Let\u2019s try this with Python.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myname='Ayushi'\r\n&gt;&gt;&gt; Myname<\/pre>\n<p><strong>Traceback (most recent call last):<\/strong><\/p>\n<p><strong>File \u201c&lt;pyshell#3&gt;\u201d, line 1, in &lt;module&gt;<\/strong><\/p>\n<p><strong>Myname<\/strong><\/p>\n<p><strong>NameError: name \u2018Myname\u2019 is not defined<\/strong><\/p>\n<p>As you can see, this raised a NameError. This means that Python is indeed case-sensitive.<\/p>\n<p><strong>Q.6. How long can an identifier be in Python?<\/strong><\/p>\n<p>According to the official Python documentation, an identifier can be of any length. However, PEP 8 suggests that you should limit all lines to a maximum of 79 characters. Also, PEP 20 says &#8216;readability counts&#8217;. So, a very long identifier will violate PEP-8 and PEP-20.<\/p>\n<p>Apart from that, there are certain rules we must follow to name one:<\/p>\n<ul>\n<li>It can only begin with an underscore or a character from A-Z or a-z.<\/li>\n<li>The rest of it can contain anything from the following: A-Z\/a-z\/_\/0-9.<\/li>\n<li>Python is case-sensitive, as we discussed in the previous question.<\/li>\n<li>Keywords cannot be used as identifiers. Python has the following keywords:<\/li>\n<\/ul>\n<table style=\"height: 220px\" width=\"603\">\n<tbody>\n<tr>\n<td>and<\/td>\n<td>def<\/td>\n<td>False<\/td>\n<td>import<\/td>\n<td>not<\/td>\n<td>True<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td>as<\/td>\n<td>del<\/td>\n<td>finally<\/td>\n<td>in<\/td>\n<td>or<\/td>\n<td>try<\/td>\n<\/tr>\n<tr>\n<td>assert<\/td>\n<td>elif<\/td>\n<td>for<\/td>\n<td>is<\/td>\n<td>pass<\/td>\n<td>while<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td>break<\/td>\n<td>else<\/td>\n<td>from<\/td>\n<td>lambda<\/td>\n<td>print<\/td>\n<td>with<\/td>\n<\/tr>\n<tr>\n<td>class<\/td>\n<td>except<\/td>\n<td>global<\/td>\n<td>None<\/td>\n<td>raise<\/td>\n<td>yield<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td>continue<\/td>\n<td>exec<\/td>\n<td>if<\/td>\n<td>nonlocal<\/td>\n<td>return<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em><strong>Learn everything about <a href=\"https:\/\/data-flair.training\/blogs\/identifiers-in-python\/\">Python Identifiers<\/a><\/strong><\/em><\/p>\n<p><strong>Q.7. How would you convert a string into lowercase?<\/strong><\/p>\n<p>We use the lower() method for this.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'AyuShi'.lower()<\/pre>\n<p><strong>\u2018ayushi\u2019<\/strong><\/p>\n<p>To convert it into uppercase, then, we use upper().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'AyuShi'.upper()<\/pre>\n<p><strong>\u2018AYUSHI\u2019<\/strong><\/p>\n<p>Also, to check if a string is in all uppercase or all lowercase, we use the methods isupper() and islower().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'AyuShi'.isupper()<\/pre>\n<p><strong>False<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'AYUSHI'.isupper()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'ayushi'.islower()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '@yu$hi'.islower()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '@YU$HI'.isupper()<\/pre>\n<p><strong>True<\/strong><\/p>\n<p>So, characters like @ and $ will suffice for both cases<\/p>\n<p>Also, istitle() will tell us if a string is in title case.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'The Corpse Bride'.istitle()<\/pre>\n<p><strong>True<\/strong><\/p>\n<p><strong>Q.8. What is the pass statement in Python?<\/strong><\/p>\n<p>There may be times in our code when we haven\u2019t decided what to do yet, but we must type something for it to be syntactically correct. In such a case, we use the pass statement.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def func(*args):\r\npass\r\n&gt;&gt;&gt;<\/pre>\n<p>Similarly, the break statement breaks out of a loop.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for i in range(7):\r\nif i==3: break\r\nprint(i)<\/pre>\n<p><strong>1<\/strong><\/p>\n<p><strong>2<\/strong><\/p>\n<p>Finally, the continue statement skips to the next iteration.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for i in range(7):\r\nif i==3: continue\r\nprint(i)<\/pre>\n<p><strong>1<\/strong><\/p>\n<p><strong>2<\/strong><\/p>\n<p><strong>4<\/strong><\/p>\n<p><strong>5<\/strong><\/p>\n<p><strong>6<\/strong><\/p>\n<p>Hope you have read all the basic Python Interview Questions and Answers. Now, let&#8217;s move towards the second part of the blog &#8211; Most asked Python Interview Questions and Answers for freshers<\/p>\n<h3>Frequently Asked Python Interview Questions and Answers for Freshers<\/h3>\n<p>While solving or answering these questions, if you feel any difficulty, comment us. DataFlair is always ready to help you.<\/p>\n<p><strong>Q.9. Explain help() and dir() functions in Python.<\/strong><\/p>\n<p>The help() function displays the documentation string and help for its argument.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; import copy\r\n&gt;&gt;&gt; help(copy.copy)<\/pre>\n<p>Help on function copy in module copy:<\/p>\n<p>copy(x)<\/p>\n<p>Shallow copy operation on arbitrary Python objects.<\/p>\n<p>See the module\u2019s __doc__ string for more info.<\/p>\n<p>The dir() function displays all the members of an object(any kind).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dir(copy.copy)<\/pre>\n<p><strong>[\u2018__annotations__\u2019, \u2018__call__\u2019, \u2018__class__\u2019, \u2018__closure__\u2019, \u2018__code__\u2019, \u2018__defaults__\u2019, \u2018__delattr__\u2019, \u2018__dict__\u2019, \u2018__dir__\u2019, \u2018__doc__\u2019, \u2018__eq__\u2019, \u2018__format__\u2019, \u2018__ge__\u2019, \u2018__get__\u2019, \u2018__getattribute__\u2019, \u2018__globals__\u2019, \u2018__gt__\u2019, \u2018__hash__\u2019, \u2018__init__\u2019, \u2018__init_subclass__\u2019, \u2018__kwdefaults__\u2019, \u2018__le__\u2019, \u2018__lt__\u2019, \u2018__module__\u2019, \u2018__name__\u2019, \u2018__ne__\u2019, \u2018__new__\u2019, \u2018__qualname__\u2019, \u2018__reduce__\u2019, \u2018__reduce_ex__\u2019, \u2018__repr__\u2019, \u2018__setattr__\u2019, \u2018__sizeof__\u2019, \u2018__str__\u2019, \u2018__subclasshook__\u2019]<\/strong><\/p>\n<p><strong>Q.10. How do you get a list of all the keys in a dictionary?<\/strong><\/p>\n<p>Be specific in these type of Python Interview Questions and Answers.<\/p>\n<p>For this, we use the function keys().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; mydict={'a':1,'b':2,'c':3,'e':5}\r\n&gt;&gt;&gt; mydict.keys()<\/pre>\n<p><strong>dict_keys([\u2018a\u2019, \u2018b\u2019, \u2018c\u2019, \u2018e\u2019])<\/strong><\/p>\n<p class=\"df-text-bold df-text-red\" style=\"text-align: center\">Wait!! Have you developed any Python Project yet?<\/p>\n<p class=\"df-text-bold\" style=\"text-align: center\">Practice with <a href=\"https:\/\/data-flair.training\/blogs\/python-projects-with-source-code\/\">Top Python Projects with source code<\/a> and become job-ready<\/p>\n<p><strong>Q.11. What is slicing?<\/strong><\/p>\n<p>Slicing is a technique that allows us to retrieve only a part of a list, tuple, or string. For this, we use the slicing operator [].<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; (1,2,3,4,5)[2:4]<\/pre>\n<p><strong>(3, 4)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [7,6,8,5,9][2:]<\/pre>\n<p><strong>[8, 5, 9]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'Hello'[:-1]<\/pre>\n<p><strong>\u2018Hell\u2019<\/strong><\/p>\n<p><strong>Q.12.\u00a0How would you declare a comment in Python?<\/strong><\/p>\n<p>Unlike languages like C++, Python does not have multiline comments. All it has is octothorpe (#). Anything following a hash is considered a comment, and the interpreter ignores it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; #line 1 of comment\r\n&gt;&gt;&gt; #line 2 of comment<\/pre>\n<p>In fact, you can place a comment anywhere in your code. You can use it to explain your code.<\/p>\n<p><strong>Q.13. How will you check if all characters in a string are alphanumeric?<\/strong><\/p>\n<p>For this, we use the method isalnum().<\/p>\n<p><strong>Q.14. How will you capitalize the first letter of a string?<\/strong><\/p>\n<p>Simply using the method capitalize().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'ayushi'.capitalize()<\/pre>\n<p><strong>\u2018Ayushi\u2019<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; type(str.capitalize)<\/pre>\n<p><strong>&lt;class \u2018method_descriptor\u2019&gt;<\/strong><\/p>\n<p>However, it will let other characters be.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '@yushi'.capitalize()<\/pre>\n<p><strong>\u2018@yushi\u2019<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'Ayushi123'.isalnum()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'Ayushi123!'.isalnum()<\/pre>\n<p><strong>False<\/strong><\/p>\n<p>Other methods that we have include:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '123.3'.isdigit()<\/pre>\n<p><strong>False<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '123'.isnumeric()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'ayushi'.islower()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'Ayushi'.isupper()<\/pre>\n<p><strong>False<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'Ayushi'.istitle()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; ' '.isspace()<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '123F'.isdecimal()<\/pre>\n<p><strong>False<\/strong><\/p>\n<p><strong>Q.15. We know Python is all the rage these days. But to be truly accepting of a great technology, you must know its pitfalls as well. Would you like to talk about this?<\/strong><\/p>\n<p>Of course. To be truly yourself, you must be accepting of your flaws. Only then can you move forward to work on them. <a href=\"https:\/\/www.python.org\/about\/gettingstarted\/\">Python<\/a> has its flaws too:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Python-Interview-Question-limitations-of-Python.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-70360\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Python-Interview-Question-limitations-of-Python.png\" alt=\"Python Interview Question - limitations of Python\" width=\"543\" height=\"289\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Python-Interview-Question-limitations-of-Python.png 752w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Python-Interview-Question-limitations-of-Python-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Python-Interview-Question-limitations-of-Python-300x160.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Python-Interview-Question-limitations-of-Python-520x277.png 520w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/a><\/p>\n<ul>\n<li>Python\u2019s interpreted nature imposes a speed penalty on it.<\/li>\n<li>While Python is great for a lot of things, it is weak in mobile computing, and in browsers.<\/li>\n<li>Being dynamically-typed, Python uses duck-typing (If it looks like a duck, it must be a duck). This can raise runtime errors.<\/li>\n<li>Python has underdeveloped database access layers. This renders it a less-than-perfect choice for huge database applications.<\/li>\n<li>And then, well, of course. Being easy makes it addictive. Once a Python-coder, always a Python coder.<\/li>\n<\/ul>\n<p><strong>Q.16. With Python, how do you find out which directory you are currently in?<\/strong><\/p>\n<p>To find this, we use the function\/method getcwd(). We import it from the module os.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; import os\r\n&gt;&gt;&gt; os.getcwd()<\/pre>\n<p><strong>\u2018C:\\\\Users\\\\lifei\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python36-32\u2019<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; type(os.getcwd)<\/pre>\n<p><strong>&lt;class \u2018builtin_function_or_method\u2019&gt;<\/strong><\/p>\n<p>We can also change the current working directory with chdir().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; os.chdir('C:\\\\Users\\\\lifei\\\\Desktop')\r\n&gt;&gt;&gt; os.getcwd()<\/pre>\n<p><strong>\u2018C:\\\\Users\\\\lifei\\\\Desktop\u2019<\/strong><\/p>\n<p><strong>Q.17. How do you insert an object at a given index in Python?<\/strong><\/p>\n<p>Let\u2019s build a list first.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=[1,2,4]<\/pre>\n<p>Now, we use the method insert. The first argument is the index at which to insert, the second is the value to insert.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a.insert(2,3)\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>[1, 2, 3, 4]<\/strong><\/p>\n<p><strong>Q.18. And how do you reverse a list?<\/strong><\/p>\n<p>Using the reverse() method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a.reverse()\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>[4, 3, 2, 1]<\/strong><\/p>\n<p>You can also do it via slicing from right to left:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a[::-1]\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>[1, 2, 3, 4]<\/strong><\/p>\n<p>This gives us the original list because we already reversed it once. However, this does not modify the original list to reverse it.<\/p>\n<p><strong>Q.19. What is the Python interpreter prompt?<\/strong><\/p>\n<p>This is the following sign for <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-interpreter\/\">Python Interpreter<\/a><\/strong><\/em>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt;<\/pre>\n<p>If you have worked with the IDLE, you will see this prompt.<\/p>\n<p><strong>Q.20. How does a function return values?<\/strong><\/p>\n<p>A function uses the \u2018return\u2019 keyword to return a value. Take a look:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def add(a,b):\r\nreturn a+b<\/pre>\n<p><strong>Q.21. How would you define a block in Python?<\/strong><\/p>\n<p>For any kind of statements, we possibly need to define a block of code under them. However, Python does not support curly braces. This means we must end such statements with colons and then indent the blocks under those with the same amount.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; if 3&gt;1:\r\nprint(\"Hello\")\r\nprint(\"Goodbye\")<\/pre>\n<p><strong>Hello<\/strong><\/p>\n<p><strong>Goodbye<\/strong><\/p>\n<p><strong>Q.22. Why do we need break and continue in Python?<\/strong><\/p>\n<p>Both break and continue are statements that control flow in <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-loops\/\">Python loops<\/a><\/strong><\/em>. break stops the current loop from executing further and transfers the control to the next block. continue jumps to the next iteration of the loop without exhausting it.<\/p>\n<p><strong>Q.23. Will the do-while loop work if you don\u2019t end it with a semicolon?<\/strong><\/p>\n<p><strong>Trick question!<\/strong> Python does not support an intrinsic do-while loop. Secondly, to terminate do-while loops is a necessity for languages like C++.<\/p>\n<p><strong>Q.24. In one line, show us how you\u2019ll get the max alphabetical character from a string.<\/strong><\/p>\n<p>For this, we\u2019ll simply use the max function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; max('flyiNg')<\/pre>\n<p>\u2018y\u2019<\/p>\n<p>The following are the ASCII values for all the letters of this string-<\/p>\n<p>f- 102<\/p>\n<p>l- 108<\/p>\n<p>y- 121<\/p>\n<p>i- 105<\/p>\n<p>N- 78<\/p>\n<p>g- 103<\/p>\n<p>By this logic, try to explain the following line of code-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; max('fly{}iNg')<\/pre>\n<p><strong>\u2018}\u2019<\/strong><\/p>\n<p><strong>(Bonus: } \u2013 125)<\/strong><\/p>\n<p><strong>Q.25. What is Python good for?<\/strong><\/p>\n<p>Python is a jack of many trades, check out Applications of Python to find out more.<\/p>\n<p>Meanwhile, we\u2019ll say we can use it for:<\/p>\n<ul>\n<li>Web and Internet Development<\/li>\n<li>Desktop GUI<\/li>\n<li>Scientific and Numeric Applications<\/li>\n<li>Software Development Applications<\/li>\n<li>Applications in Education<\/li>\n<li>Applications in Business<\/li>\n<li>Database Access<\/li>\n<li>Network Programming<\/li>\n<li>Games, 3D Graphics<\/li>\n<li>Other Python Applications<\/li>\n<\/ul>\n<p><strong>Q.26. Can you name ten built-in functions in Python and explain each in brief?<\/strong><\/p>\n<p>Ten Built-in Functions, you say? Okay, here you go.<\/p>\n<p>complex()- Creates a complex number.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; complex(3.5,4)<\/pre>\n<p><strong>(3.5+4j)<\/strong><\/p>\n<p>eval()- Parses a string as an expression.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; eval('print(max(22,22.0)-min(2,3))')<\/pre>\n<p><strong>20<\/strong><\/p>\n<p>filter()- Filters in items for which the condition is true.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(filter(lambda x:x%2==0,[1,2,0,False]))<\/pre>\n<p><strong>[2, 0, False]<\/strong><\/p>\n<p>format()- Lets us format a string.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(\"a={0} but b={1}\".format(a,b))<\/pre>\n<p><strong>a=2 but b=3<\/strong><\/p>\n<p>hash()- Returns the hash value of an object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; hash(3.7)<\/pre>\n<p><strong>644245917<\/strong><\/p>\n<p>hex()- Converts an integer to a hexadecimal.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; hex(14)<\/pre>\n<p><strong>\u20180xe\u2019<\/strong><\/p>\n<p>input()- Reads and returns a line of string.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; input('Enter a number')<\/pre>\n<p>Enter a number7<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\u20187\u2019<\/pre>\n<p>len()- Returns the length of an object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len('Ayushi')<\/pre>\n<p><strong>6<\/strong><\/p>\n<p>locals()- Returns a dictionary of the current local symbol table.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; locals()<\/pre>\n<p><strong>{\u2018__name__\u2019: \u2018__main__\u2019, \u2018__doc__\u2019: None, \u2018__package__\u2019: None, \u2018__loader__\u2019: &lt;class \u2018_frozen_importlib.BuiltinImporter\u2019&gt;, \u2018__spec__\u2019: None, \u2018__annotations__\u2019: {}, \u2018__builtins__\u2019: &lt;module \u2018builtins\u2019 (built-in)&gt;, \u2018a\u2019: 2, \u2018b\u2019: 3}<\/strong><\/p>\n<p>open()- Opens a file.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; file=open('tabs.txt')<\/pre>\n<p><strong>Q.27. What will the following code output?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; word=\u2019abcdefghij\u2019\r\n&gt;&gt;&gt; word[:3]+word[3:]<\/pre>\n<p>The output is \u2018abcdefghij\u2019. The first slice gives us \u2018abc\u2019, the next gives us \u2018defghij\u2019.<\/p>\n<p><strong>Q.28. How will you convert a list into a string?<\/strong><\/p>\n<p>We will use the join() method for this.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=['one','two','three','four','five','six','seven']\r\n&gt;&gt;&gt; s=' '.join(nums)\r\n&gt;&gt;&gt; s<\/pre>\n<p><strong>\u2018one two three four five six seven\u2019<\/strong><\/p>\n<p><strong>Q.29. How will you remove a duplicate element from a list?<\/strong><\/p>\n<p>We can turn it into a set to do that.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list=[1,2,1,3,4,2]\r\n&gt;&gt;&gt; set(list)<\/pre>\n<p>{1, 2, 3, 4}<\/p>\n<p><strong>Q.30. Can you explain the life cycle of a thread?<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-70341\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread.png\" alt=\"python scripting interview questions\" width=\"644\" height=\"337\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread.png 4500w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread-150x79.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread-300x157.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread-768x402.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread-1024x536.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/technical-python-interview-questions-life-cycle-of-a-thread-520x272.png 520w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<ul>\n<li>To create a thread, we create a class that we make override the run method of the thread class. Then, we instantiate it.<\/li>\n<li>A thread that we just created is in the new state. When we make a call to start() on it, it forwards the threads for scheduling. These are in the ready state.<\/li>\n<li>When execution begins, the thread is in the running state.<\/li>\n<li>Calls to methods like sleep() and join() make a thread wait. Such a thread is in the waiting\/blocked state.<\/li>\n<li>When a thread is done waiting or executing, other waiting threads are sent for scheduling.<\/li>\n<li>A running thread that is done executing terminates and is in the dead state.<\/li>\n<\/ul>\n<h3>Basic Python Program Interview Questions and Answers<\/h3>\n<p><strong>Q.31. What is a dictionary in Python?<\/strong><\/p>\n<p>A\u00a0<em><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-dictionary\/\">python dictionary<\/a><\/strong><\/em>\u00a0is something I have never seen in other languages like C++ or Java programming. It holds key-value pairs.<\/p>\n<div class=\"EnlighterJSWrapper enlighterEnlighterJSWrapper\">\n<ol class=\"hoverEnabled enlighterEnlighterJS EnlighterJS\">\n<li class=\" odd\"><span class=\"\">&gt;&gt;&gt; roots=<\/span><span class=\"br0\">{<\/span><span class=\"nu0\">25<\/span><span class=\"\">:<\/span><span class=\"nu0\">5<\/span><span class=\"\">,<\/span><span class=\"nu0\">16<\/span><span class=\"\">:<\/span><span class=\"nu0\">4<\/span><span class=\"\">,<\/span><span class=\"nu0\">9<\/span><span class=\"\">:<\/span><span class=\"nu0\">3<\/span><span class=\"\">,<\/span><span class=\"nu0\">4<\/span><span class=\"\">:<\/span><span class=\"nu0\">2<\/span><span class=\"\">,<\/span><span class=\"nu0\">1<\/span><span class=\"\">:<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">}<\/span><\/li>\n<li class=\" even\"><span class=\"\">&gt;&gt;&gt; <\/span><span class=\"kw1\">type<\/span><span class=\"br0\">(<\/span><span class=\"\">roots<\/span><span class=\"br0\">)<\/span><\/li>\n<\/ol>\n<\/div>\n<p><strong>&lt;class \u2018dict\u2019&gt;<\/strong><\/p>\n<div class=\"EnlighterJSWrapper enlighterEnlighterJSWrapper\">\n<ol class=\"hoverEnabled enlighterEnlighterJS EnlighterJS\">\n<li class=\" odd\"><span class=\"\">&gt;&gt;&gt; roots<\/span><span class=\"br0\">[<\/span><span class=\"nu0\">9<\/span><span class=\"br0\">]<\/span><\/li>\n<\/ol>\n<\/div>\n<p><strong>3<\/strong><\/p>\n<p>A dictionary is mutable, and we can also use a comprehension to create it.<\/p>\n<div class=\"EnlighterJSWrapper enlighterEnlighterJSWrapper\">\n<ol class=\"hoverEnabled enlighterEnlighterJS EnlighterJS\">\n<li class=\" odd\"><span class=\"\">&gt;&gt;&gt; roots=<\/span><span class=\"br0\">{<\/span><span class=\"\">x**<\/span><span class=\"nu0\">2<\/span><span class=\"\">\ud83d\ude21 for x in <\/span><span class=\"kw1\">range<\/span><span class=\"br0\">(<\/span><span class=\"nu0\">5<\/span><span class=\"\">,<\/span><span class=\"nu0\">0<\/span><span class=\"\">,-<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">)<\/span><span class=\"br0\">}<\/span><\/li>\n<li class=\" even\"><span class=\"\">&gt;&gt;&gt; roots<\/span><\/li>\n<\/ol>\n<\/div>\n<p><strong>{25: 5, 16: 4, 9: 3, 4: 2, 1: 1}<\/strong><\/p>\n<p><strong>Q.32. Explain the \/\/, %, and ** operators in Python.<\/strong><\/p>\n<p>The \/\/ operator performs floor division. It will return the integer part of the result on division.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 7\/\/2<\/pre>\n<p><strong>3<\/strong><\/p>\n<p>Normal division would return 3.5 here.<\/p>\n<p>Similarly, ** performs exponentiation. a**b returns the value of a raised to the power b.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2**10<\/pre>\n<p><strong>1024<\/strong><\/p>\n<p>Finally, % is for modulus. This gives us the value left after the highest achievable division.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 13%7<\/pre>\n<p><strong>6<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3.5%1.5<\/pre>\n<p><strong>0.5<\/strong><\/p>\n<p><strong>Q.33. What do you know about relational operators in Python.<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-70334\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators.png\" alt=\"Top python interview questions with answers\" width=\"534\" height=\"264\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators.png 790w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators-150x74.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators-300x148.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators-768x379.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Python-interview-questions-and-answers-Relational-Operators-520x257.png 520w\" sizes=\"auto, (max-width: 534px) 100vw, 534px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Relational operators compare values.<\/p>\n<p>Less than (&lt;) If the value on the left is lesser, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'hi'&lt;'Hi'<\/pre>\n<p><strong>False<\/strong><br \/>\nGreater than (&gt;) If the value on the left is greater, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 1.1+2.2&gt;3.3<\/pre>\n<p><strong>True<\/strong><\/p>\n<p>This is because of the flawed floating-point arithmetic in Python, due to hardware dependencies.<\/p>\n<p>Less than or equal to (&lt;=) If the value on the left is lesser than or equal to, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3.0&lt;=3<\/pre>\n<p><strong>True<\/strong><\/p>\n<p>Greater than or equal to (&gt;=) If the value on the left is greater than or equal to, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; True&gt;=False<\/pre>\n<p><strong>True<\/strong><\/p>\n<p>Equal to (==) If the two values are equal, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; {1,3,2,2}=={1,2,3}<\/pre>\n<p><strong>True<\/strong><\/p>\n<p>Not equal to (!=) If the two values are unequal, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; True!=0.1<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; False!=0.1<\/pre>\n<p><strong>True<\/strong><\/p>\n<p><em>You will surely face a question from Python Operators. There are chances that question may be in an indirect way. Prepare yourself for it with the best guide &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/python-operator\/\"><strong>Python Operators<\/strong><\/a><\/em><\/p>\n<p><strong>Q.34. What are assignment operators in Python?<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-70346\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators.png\" alt=\"python coding interview questions\" width=\"593\" height=\"315\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators.png 790w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators-300x159.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators-768x408.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/Interview-questions-for-Python-assignment-operators-520x276.png 520w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>We can combine all arithmetic operators with the assignment symbol.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=7\r\n&gt;&gt;&gt; a+=1\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>8<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a-=1\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>7<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a*=2\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>14<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a\/=2\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>7.0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a**=2\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>49.0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a\/\/=3\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>16.0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a%=4\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>0.0<\/strong><\/p>\n<p><strong>Q.35. Explain logical operators in Python.<\/strong><\/p>\n<p>We have three logical operators- and, or, not.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; False and True<\/pre>\n<p><strong>False<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 7&lt;7 or True<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; not 2==2<\/pre>\n<p><strong>False<\/strong><\/p>\n<p><strong>Q.36. What are membership operators?<\/strong><\/p>\n<p>With the operators \u2018in\u2019 and \u2018not in\u2019, we can confirm if a value is a member in another.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'me' in 'disappointment'<\/pre>\n<p><strong>True<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'us' not in 'disappointment'<\/pre>\n<p><strong>True<\/strong><\/p>\n<p><strong>Q.37. Explain identity operators in Python.<\/strong><\/p>\n<p>The operators \u2018is\u2019 and \u2018is not\u2019 tell us if two values have the same identity.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 10 is '10'<\/pre>\n<p><strong>False<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; True is not False<\/pre>\n<p><strong>True<\/strong><\/p>\n<p><strong>Q.38. Finally, tell us about bitwise operators in Python.<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-70338\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators.png\" alt=\"python interview questions for freshers\" width=\"580\" height=\"292\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators.png 790w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators-300x151.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators-768x387.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/09\/python-interview-questions-bitwise-operators-520x262.png 520w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>These operate on values bit by bit.<\/p>\n<p>AND (&amp;) This performs &amp; on each bit pair.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 0b110 &amp; 0b010<\/pre>\n<p><strong>2<\/strong><\/p>\n<p>OR (|) This performs | on each bit pair.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3|2<\/pre>\n<p><strong>3<\/strong><\/p>\n<p>XOR (^) This performs an exclusive-OR operation on each bit pair.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3^2<\/pre>\n<p><strong>1<\/strong><\/p>\n<p>Binary One\u2019s Complement (~) This returns the one\u2019s complement of a value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; ~2<\/pre>\n<p><strong>-3<\/strong><\/p>\n<p>Binary Left-Shift (&lt;&lt;) This shifts the bits to the left by the specified amount.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 1&lt;&lt;2<\/pre>\n<p><strong>4<\/strong><\/p>\n<p>Here, 001 was shifted to the left by two places to get 100, which is binary for 4.<\/p>\n<p>Binary Right-Shift (&gt;&gt;)<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 4&gt;&gt;2<\/pre>\n<p><strong>1<\/strong><\/p>\n<p><strong>Q.39. What data types does Python support?<\/strong><\/p>\n<p>Python provides us with five kinds of data types:<\/p>\n<p><strong>Numbers &#8211;<\/strong> Numbers use to hold numerical values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=7.0\r\n&gt;&gt;&gt;<\/pre>\n<p><strong>Strings &#8211;<\/strong> A string is a sequence of characters. We declare it using single or double quotes.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; title=\"Ayushi's Book\"<\/pre>\n<p><strong>Lists &#8211;<\/strong> A list is an ordered collection of values, and we declare it using square brackets.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; colors=['red','green','blue']\r\n&gt;&gt;&gt; type(colors)<\/pre>\n<p><strong>&lt;class \u2018list\u2019&gt;<\/strong><\/p>\n<p><strong>Tuples &#8211;<\/strong> A tuple, like a list, is an ordered collection of values. The difference. However, is that a tuple is immutable. This means that we cannot change a value in it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; name=('Ayushi','Sharma')\r\n&gt;&gt;&gt; name[0]='Avery'<\/pre>\n<p><strong>Traceback (most recent call last):<\/strong><\/p>\n<p><strong>File \u201c&lt;pyshell#129&gt;\u201d, line 1, in &lt;module&gt; <\/strong><\/p>\n<p><strong>name[0]=\u2019Avery\u2019<\/strong><\/p>\n<p><strong>TypeError: \u2018tuple\u2019 object does not support item assignment<\/strong><\/p>\n<p><strong>Dictionary &#8211;<\/strong> A dictionary is a data structure that holds key-value pairs. We declare it using curly braces.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; squares={1:1,2:4,3:9,4:16,5:25}\r\n&gt;&gt;&gt; type(squares)<\/pre>\n<p><strong>&lt;class \u2018dict\u2019&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; type({})<\/pre>\n<p><strong>&lt;class \u2018dict\u2019&gt;<\/strong><\/p>\n<p>We can also use a dictionary comprehension:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; squares={x:x**2 for x in range(1,6)}\r\n&gt;&gt;&gt; squares<\/pre>\n<p><strong>{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}<\/strong><\/p>\n<p><em><strong>Don&#8217;t miss the complete guide for <a href=\"https:\/\/data-flair.training\/blogs\/python-variables-and-data-types\/\">Python Data Types and Variables<\/a><\/strong><\/em><\/p>\n<p><strong>Q.40. What is a docstring?<\/strong><\/p>\n<p>A docstring is a documentation string that we use to explain what a construct does. We place it as the first thing under a function, class, or a method, to describe what it does. We declare a docstring using three sets of single or double-quotes.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def sayhi():\r\n\"\"\"\r\nThe function prints Hi\r\n\"\"\"\r\nprint(\"Hi\")\r\n&gt;&gt;&gt; sayhi()<\/pre>\n<p><strong>Hi<\/strong><\/p>\n<p>To get a function\u2019s docstring, we use its __doc__ attribute.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; sayhi.__doc__<\/pre>\n<p>\u2018\\n\\tThis function prints Hi\\n\\t\u2019<\/p>\n<p>A docstring, unlike a comment, is retained at runtime.<\/p>\n<p><strong>Q.41. How would you convert a string into an int in Python?<\/strong><\/p>\n<p>If a string contains only numerical characters, you can convert it into an integer using the int() function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; int('227')<\/pre>\n<p><strong>227<\/strong><\/p>\n<p>Let\u2019s check the types:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; type('227')<\/pre>\n<p><strong>&lt;class \u2018str\u2019&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; type(int('227'))<\/pre>\n<p><strong>&lt;class \u2018int\u2019&gt;<\/strong><\/p>\n<p><strong>Q.42. How do you take input in Python?<\/strong><\/p>\n<p>For taking input from the user, we have the function input(). In Python 2, we had another function raw_input().<\/p>\n<p>The input() function takes, as an argument, the text to be displayed for the task:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=input('Enter a number')<\/pre>\n<p><strong>Enter a number7<\/strong><\/p>\n<p>But if you have paid attention, you know that it takes input in the form of a string.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; type(a)<\/pre>\n<p><strong>&lt;class \u2018str\u2019&gt;<\/strong><\/p>\n<p>Multiplying this by 2 gives us this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a*=2\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>\u201977\u2019<\/strong><\/p>\n<p>So, what if we need to work on an integer instead?<\/p>\n<p>We use the int() function for this.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=int(input('Enter a number'))<\/pre>\n<p><strong>Enter a number7<\/strong><\/p>\n<p>Now when we multiply it by 2, we get this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a*=2\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>14<\/strong><\/p>\n<p><strong>Q.43. What is a function?<\/strong><\/p>\n<p>When we want to execute a sequence of statements, we can give it a name. Let\u2019s define a function to take two numbers and return the greater number.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def greater(a,b):\r\nreturn a is a&gt;b else b\r\n&gt;&gt;&gt; greater(3,3.5)<\/pre>\n<p><strong>3.5<\/strong><\/p>\n<p><strong>Q.44. What is recursion?<\/strong><\/p>\n<p>When a function makes a call to itself, it is termed <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/recursion-in-python\/\">recursion<\/a><\/strong><\/em>. But then, in order for it to avoid forming an infinite loop, we must have a base condition.<\/p>\n<p>Let\u2019s take an example.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def facto(n):\r\nif n==1: return 1\r\nreturn n*facto(n-1)\r\n&gt;&gt;&gt; facto(4)<\/pre>\n<p><strong>24<\/strong><\/p>\n<p><strong>Q.45. What does the function zip() do?<\/strong><\/p>\n<p>One of the less common functions with beginners, zip() returns an iterator of tuples.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(zip(['a','b','c'],[1,2,3]))<\/pre>\n<p><strong>[(\u2018a\u2019, 1), (\u2018b\u2019, 2), (\u2018c\u2019, 3)]<\/strong><\/p>\n<p>Here, it pairs items from the two lists and creates tuples with those. But it doesn\u2019t have to be lists.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(zip(('a','b','c'),(1,2,3)))<\/pre>\n<p><strong>[(\u2018a\u2019, 1), (\u2018b\u2019, 2), (\u2018c\u2019, 3)]<\/strong><\/p>\n<p><strong>Q.46. How do you calculate the length of a string?<\/strong><\/p>\n<p>This is simple. We call the function len() on the string we want to calculate the length of.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len('Ayushi Sharma')<\/pre>\n<p><strong>13<\/strong><\/p>\n<p><strong>Q.47. Explain Python List Comprehension.<\/strong><\/p>\n<p>The <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-list-comprehension\/\">list comprehension in python<\/a><\/strong><\/em> is a way to declare a list in one line of code. Let\u2019s take a look at one such example.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [i for i in range(1,11,2)]<\/pre>\n<p><strong>[1, 3, 5, 7, 9]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [i*2 for i in range(1,11,2)]<\/pre>\n<p><strong>[2, 6, 10, 14, 18]<\/strong><\/p>\n<p><strong>Q.48. How do you get all values from a Python dictionary?<\/strong><\/p>\n<p>We saw previously, to get all keys from a dictionary, we make a call to the keys() method. Similarly, for values, we use the method values().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'd' in {'a':1,'b':2,'c':3,'d':4}.values()<\/pre>\n<p><strong>False<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 4 in {'a':1,'b':2,'c':3,'d':4}.values()<\/pre>\n<p><strong>True<\/strong><\/p>\n<p><strong>Q.49. What if you want to toggle case for a Python string?<\/strong><\/p>\n<p>We have the swapcase() method from the str class to do just that.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'AyuShi'.swapcase()<\/pre>\n<p><strong>\u2018aYUsHI\u2019<\/strong><\/p>\n<p>Let\u2019s apply some concepts now, shall we? Questions 50 through 52 assume the string \u2018I love Python\u2019. You need to do the needful.<\/p>\n<p><strong>Q.50. Write code to print only upto the letter t.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; i=0\r\n&gt;&gt;&gt; while s[i]!='t':\r\nprint(s[i],end=\u2019\u2019)\r\ni+=1<\/pre>\n<p>I love Py<\/p>\n<p><strong>Q.51. Write code to print everything in the string except the spaces.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for i in s:\r\nif i==' ': continue\r\nprint(i,end='')<\/pre>\n<p><strong>IlovePython<\/strong><\/p>\n<p><strong>Q.52. Now, print this string five times in a row.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for i in range(6):\r\nprint(s)<\/pre>\n<p><strong>I love Python<\/strong><\/p>\n<p><strong>I love Python<\/strong><\/p>\n<p><strong>I love Python<\/strong><\/p>\n<p><strong>I love Python<\/strong><\/p>\n<p><strong>I love Python<\/strong><\/p>\n<p><strong>I love Python<\/strong><\/p>\n<p>Okay, moving on to more domains to conquer.<\/p>\n<p><strong>Q.53. What is the purpose of bytes() in Python?<\/strong><\/p>\n<p>bytes() is a built-in function in Python that returns an immutable bytes object. Let\u2019s take an example.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; bytes([2,4,8])<\/pre>\n<p><strong>b\u2019\\x02\\x04\\x08\u2032<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; bytes(5)<\/pre>\n<p><strong>b\u2019\\x00\\x00\\x00\\x00\\x00\u2032<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; bytes('world','utf-8')<\/pre>\n<p><strong>b\u2019world\u2019<\/strong><\/p>\n<p><strong>Q.54. What is a control flow statement?<\/strong><\/p>\n<p>A Python program usually starts to execute from the first line. From there, it moves through each statement just once and as soon as it\u2019s done with the last statement, it transactions the program. However, sometimes, we may want to take a more twisted path through the code. Control flow statements let us disturb the normal execution flow of a program and bend it to our will.<\/p>\n<p><strong>Q.55.\u00a0Create a new list to convert the following list of number strings to a list of numbers.<\/strong><\/p>\n<p><strong>nums=[\u201822\u2019,\u201968\u2019,\u2019110\u2019,\u201989\u2019,\u201931\u2019,\u201912\u2019]<\/strong><\/p>\n<p>We will use the int() function with a list comprehension to convert these strings into integers and put them in a list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [int(i) for i in nums]<\/pre>\n<p><strong>[22, 68, 110, 89, 31, 12]<\/strong><\/p>\n<p><strong>Q.56. Given the first and last names of all employees in your firm, what data type will you use to store it?<\/strong><\/p>\n<p>I can use a dictionary to store that. It would be something like this-<\/p>\n<p>{\u2018first_name\u2019:\u2019Ayushi\u2019,\u2019second_name\u2019:\u2019Sharma\u2019<\/p>\n<h3>Top Python Interview Questions and Answers<\/h3>\n<p><strong>Q.57.\u00a0 How would you work with numbers other than those in the decimal number system?<\/strong><\/p>\n<p>With Python, it is possible to type numbers in binary, octal, and hexadecimal.<\/p>\n<p>Binary numbers are made of 0 and 1. To type in binary, we use the prefix 0b or 0B.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; int(0b1010)<\/pre>\n<p><strong>10<\/strong><\/p>\n<p>To convert a number into its binary form, we use bin().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; bin(0xf)<\/pre>\n<p><strong>\u20180b1111\u2019<\/strong><\/p>\n<p>Octal numbers may have digits from 0 to 7. We use the prefix 0o or 0O.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; oct(8)<\/pre>\n<p><strong>\u20180o10\u2019<\/strong><\/p>\n<p>Hexadecimal numbers may have digits from 0 to 15. We use the prefix 0x or 0X.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; hex(16)<\/pre>\n<p><strong>\u20180x10\u2019<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; hex(15)<\/pre>\n<p><strong>\u20180xf\u2019<\/strong><\/p>\n<p><strong><em>DataFlair&#8217;s latest article on <a href=\"https:\/\/data-flair.training\/blogs\/python-number-types-conversion\/\">Python Numbers<\/a> with Examples<\/em><\/strong><\/p>\n<p><strong>Q.58. What does the following code output?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def extendList(val, list=[]):\r\nlist.append(val)\r\nreturn list\r\n&gt;&gt;&gt; list1 = extendList(10)\r\n&gt;&gt;&gt; list2 = extendList(123,[])\r\n&gt;&gt;&gt; list3 = extendList('a')\r\n&gt;&gt;&gt; list1,list2,list3<\/pre>\n<p><strong>([10, \u2018a\u2019], [123], [10, \u2018a\u2019])<\/strong><\/p>\n<p>You\u2019d expect the output to be something like this:<\/p>\n<p><strong>([10],[123],[\u2018a\u2019])<\/strong><\/p>\n<p>Well, this is because the list argument does not initialize to its default value ([]) every time we make a call to the function. Once we define the function, it creates a new list. Then, whenever we call it again without a list argument, it uses the same list. This is because it calculates the expressions in the default arguments when we define the function, not when we call it.<\/p>\n<p><strong>Q.59.\u00a0 How many arguments can the range() function take?<\/strong><\/p>\n<p>The range() function in Python can take up to 3 arguments. Let\u2019s see this one by one.<\/p>\n<p><strong>a. One argument<\/strong><\/p>\n<p>When we pass only one argument, it takes it as the stop value. Here, the start value is 0, and the step value is +1.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(5))<\/pre>\n<p><strong>[0, 1, 2, 3, 4]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(-5))<\/pre>\n<p><strong>[]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(0))<\/pre>\n<p><strong>[]<\/strong><\/p>\n<p><strong>b. Two arguments<\/strong><\/p>\n<p>When we pass two arguments, the first one is the start value, and the second is the stop value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(2,7))<\/pre>\n<p><strong>[2, 3, 4, 5, 6]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(7,2))<\/pre>\n<p><strong>[]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(-3,4))<\/pre>\n<p><strong>[-3, -2, -1, 0, 1, 2, 3]<\/strong><\/p>\n<p><strong>c. Three arguments<\/strong><\/p>\n<p>Here, the first argument is the start value, the second is the stop value, and the third is the step value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(2,9,2))<\/pre>\n<p><strong>[2, 4, 6, 8]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(range(9,2,-1))<\/pre>\n<p><strong>[9, 8, 7, 6, 5, 4, 3]<\/strong><\/p>\n<p><strong>Q.60. What is PEP 8?<\/strong><\/p>\n<p>PEP 8 is a coding convention that lets us write more readable code. In other words, it is a set of recommendations.<\/p>\n<p><strong>Q.61. How is Python different from Java?<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-54737\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java.jpg\" alt=\"Python vs Java - Which is best for Beginners\" width=\"617\" height=\"323\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Difference-Between-Python-and-Java-520x272.jpg 520w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/a><\/p>\n<p>Following is the comparison of Python vs Java \u2013<\/p>\n<ul>\n<li>Java is faster than Python<\/li>\n<li>Python mandates indentation. Java needs braces.<\/li>\n<li>Python is dynamically-typed; Java is statically typed.<\/li>\n<li>Python is simple and concise; Java is verbose<\/li>\n<li>Python is interpreted<\/li>\n<li>Java is platform-independent<\/li>\n<li>Java has stronger database-access with JDBC<\/li>\n<\/ul>\n<p style=\"text-align: center\"><strong>Python vs Java, the most commonly asked python interview question for freshers. <\/strong><\/p>\n<p style=\"text-align: center\"><strong>Learn it in detail &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/python-vs-java\/\">Python vs Java<\/a> for Interview<\/strong><\/p>\n<p><strong>Q.62. What is the best code you can write to swap two numbers?<\/strong><\/p>\n<p>I can perform the swapping in one statement.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a,b=b,a<\/pre>\n<p>Here\u2019s the entire code, though-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a,b=2,3\r\n&gt;&gt;&gt; a,b=b,a\r\n&gt;&gt;&gt; a,b<\/pre>\n<p><strong>(3, 2)<\/strong><\/p>\n<p><strong>Q.63. How can you declare multiple assignments in one statement?<\/strong><\/p>\n<p>This is one of the most asked interview questions for Python freshers &#8211;<\/p>\n<p>There are two ways to do this:<\/p>\n<p><strong>First &#8211;\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a,b,c=3,4,5 #This assigns 3, 4, and 5 to a, b, and c respectively<\/pre>\n<p><strong>Second &#8211;\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=b=c=3 #This assigns 3 to a, b, and c<\/pre>\n<p><strong>Q.64. If you are ever stuck in an infinite loop, how will you break out of it?<\/strong><\/p>\n<p>For this, we press Ctrl+C. This interrupts the execution. Let\u2019s create an infinite loop to demonstrate this.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def counterfunc(n):\r\nwhile(n==7):print(n)\r\n&gt;&gt;&gt; counterfunc(7)<\/pre>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>7<\/strong><\/p>\n<p><strong>Traceback (most recent call last):<\/strong><\/p>\n<p><strong>File \u201c&lt;pyshell#332&gt;\u201d, line 1, in &lt;module&gt;<\/strong><\/p>\n<p><strong>counterfunc(7)<\/strong><\/p>\n<p><strong>File \u201c&lt;pyshell#331&gt;\u201d, line 2, in counterfunc<\/strong><\/p>\n<p><strong>while(n==7):print(n)<\/strong><\/p>\n<p><strong>KeyboardInterrupt<\/strong><\/p>\n<h3>Technical Python Interview Questions and Answers<\/h3>\n<p><strong>Q.65. How do we execute Python?<\/strong><\/p>\n<p>Python files first compile to bytecode. Then, the host executes them.<\/p>\n<p><em><strong>Revise the concept of <a href=\"https:\/\/data-flair.training\/blogs\/python-compilers\/\">Python Compiler<\/a><\/strong><\/em><\/p>\n<p><strong>Q.66. Explain Python\u2019s parameter-passing mechanism.<\/strong><\/p>\n<p>To pass its parameters to a function, Python uses pass-by-reference. If you change a parameter within a function, the change reflects in the calling function. This is its default behavior. However, when we pass literal arguments like strings, numbers, or tuples, they pass by value. This is because they are immutable.<\/p>\n<p><strong>Q.67.\u00a0What is the with statement in Python?<\/strong><\/p>\n<p>The with statement in Python ensures that cleanup code is executed when working with unmanaged resources by encapsulating common preparation and cleanup tasks. It may be used to open a file, do something, and then automatically close the file at the end. It may be used to open a database connection, do some processing, then automatically close the connection to ensure resources are closed and available for others. with will cleanup the resources even if an exception is thrown. This statement is like the using statement in C#.<br \/>\nConsider you put some code in a try block, then in the finally block, you close any resources used. The with statement is like syntactic sugar for that.<\/p>\n<p>The syntax of this control-flow structure is:<\/p>\n<p><strong>with expression [as variable]:<br \/>\n&#8230;.with-block<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; with open('data.txt') as data:\r\n#processing statements<\/pre>\n<p><strong>Q.68. How is a .pyc file different from a .py file?<\/strong><\/p>\n<p>While both files hold bytecode, .pyc is the compiled version of a Python file. It has platform-independent bytecode. Hence, we can execute it on any platform that supports the .pyc format. Python automatically generates it to improve performance(in terms of load time, not speed).<\/p>\n<h4>Python OOPS Interview Questions and Answers<\/h4>\n<p><strong>Q.69. What makes Python object-oriented?<\/strong><\/p>\n<p>Again the frequently asked Python Interview Question<\/p>\n<p>Python is object-oriented because it follows the Object-Oriented programming paradigm. This is a paradigm that revolves around classes and their instances (objects). With this kind of programming, we have the following features:<\/p>\n<ul>\n<li>Encapsulation<\/li>\n<li>Abstraction<\/li>\n<li>Inheritance<\/li>\n<li>Polymorphism<\/li>\n<li>Data hiding<\/li>\n<\/ul>\n<p><strong>Q.70. How many types of objects does Python support?<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/python-object\/\"><em><strong>Objects in Python<\/strong><\/em><\/a> are mutable and immutable. Let\u2019s talk about these.<\/p>\n<p><strong>Immutable objects-<\/strong> Those which do not let us modify their contents. Examples of these will be tuples, booleans, strings, integers, floats, and complexes. Iterations on such objects are faster.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; tuple=(1,2,4)\r\n&gt;&gt;&gt; tuple<\/pre>\n<p><strong>(1, 2, 4)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2+4j<\/pre>\n<p><strong>(2+4j)<\/strong><\/p>\n<p><strong>Mutable objects &#8211;<\/strong> Those that let you modify their contents. Examples of these are lists, sets, and dicts. Iterations on such objects are slower.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [2,4,9]<\/pre>\n<p><strong>[2, 4, 9]<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dict1={1:1,2:2}\r\n&gt;&gt;&gt; dict1<\/pre>\n<p><strong>{1: 1, 2: 2}<\/strong><\/p>\n<p>While two equal immutable objects\u2019 reference variables share the same address, it is possible to create two mutable objects with the same content.<\/p>\n<h3>Open-ended Python Interview Questions<\/h3>\n<p>Q.71 Why do you want to work for this company?<\/p>\n<p>Q.72 Where do you see yourself in 10 years?<\/p>\n<p>Q.73 What will you bring to the table if we hire you?<\/p>\n<p>Q.74\u00a0Tell me about your best personal project. What challenges did you face, and how did it change the way you work?<\/p>\n<p>Q.75\u00a0Would you have a problem with menial tasks?<\/p>\n<p>Q.76 What makes you like Python over other languages? (The most commonly asked Python interview questions)<\/p>\n<p>So, these were some of the important Python Interview Questions and Answers. If you practiced all the above questions then you are ready to move towards the next part of DataFlair&#8217;s <a href=\"https:\/\/data-flai\"><em><strong>Python Interview Questions and Answers Series &#8211; Part 2<\/strong><\/em><\/a> for Python Interviews. I advise you not to miss a single part of this series. All these questions are specifically designed by experienced individuals to provide you with complete help for cracking your next interview.<\/p>\n<p>Start applying for the next Python Interview, you are going to crack it.<\/p>\n<p class=\"df-text-bold df-text-red\" style=\"text-align: center\"><em>Don&#8217;t Miss Out\u00a0 &#8211;\u00a0\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/job-python-resume\/\">Tips for Preparing a Perfect Python Resume<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DataFlair is devoted to help Python learners become successful in their Python careers. That&#8217;s why we are publishing an interesting and helpful series of Python Interview Questions and Answers. In this series, you will&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":70354,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[10384,10612,10616,10825,14846],"class_list":["post-10027","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-basic-interview-questions","tag-python-interview-questions-and-answers","tag-python-interview-questions-for-freshers","tag-python-scripting-interview-questions","tag-top-python-interview-questions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>150+ Python Interview Questions and Answers for Freshers [Latest] - DataFlair<\/title>\n<meta name=\"description\" content=\"150+ Python Interview Questions and Answers to make you prepare for your upcoming Python Interviews. This collection of top interview questions will boost your confidence and increase the chances to crack interview in one go.150+ Python Interview Q\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"150+ Python Interview Questions and Answers for Freshers [Latest] - DataFlair\" \/>\n<meta property=\"og:description\" content=\"150+ Python Interview Questions and Answers to make you prepare for your upcoming Python Interviews. This collection of top interview questions will boost your confidence and increase the chances to crack interview in one go.150+ Python Interview Q\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-07T05:33:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-23T04:31:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Top-Python-Interview-Questions-and-Answers.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"28 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"150+ Python Interview Questions and Answers for Freshers [Latest] - DataFlair","description":"150+ Python Interview Questions and Answers to make you prepare for your upcoming Python Interviews. This collection of top interview questions will boost your confidence and increase the chances to crack interview in one go.150+ Python Interview Q","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/","og_locale":"en_US","og_type":"article","og_title":"150+ Python Interview Questions and Answers for Freshers [Latest] - DataFlair","og_description":"150+ Python Interview Questions and Answers to make you prepare for your upcoming Python Interviews. This collection of top interview questions will boost your confidence and increase the chances to crack interview in one go.150+ Python Interview Q","og_url":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-03-07T05:33:40+00:00","article_modified_time":"2020-01-23T04:31:54+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Top-Python-Interview-Questions-and-Answers.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"28 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"150+ Python Interview Questions and Answers for Freshers [Latest]","datePublished":"2018-03-07T05:33:40+00:00","dateModified":"2020-01-23T04:31:54+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/"},"wordCount":4526,"commentCount":19,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Top-Python-Interview-Questions-and-Answers.jpg","keywords":["python basic interview questions","python interview questions and answers","python interview questions for freshers","python scripting interview questions","top Python Interview Questions"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/","url":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/","name":"150+ Python Interview Questions and Answers for Freshers [Latest] - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Top-Python-Interview-Questions-and-Answers.jpg","datePublished":"2018-03-07T05:33:40+00:00","dateModified":"2020-01-23T04:31:54+00:00","description":"150+ Python Interview Questions and Answers to make you prepare for your upcoming Python Interviews. This collection of top interview questions will boost your confidence and increase the chances to crack interview in one go.150+ Python Interview Q","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Top-Python-Interview-Questions-and-Answers.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Top-Python-Interview-Questions-and-Answers.jpg","width":802,"height":420,"caption":"Top Python Interview Questions and Answers"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"150+ Python Interview Questions and Answers for Freshers [Latest]"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/10027","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=10027"}],"version-history":[{"count":20,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/10027\/revisions"}],"predecessor-version":[{"id":70680,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/10027\/revisions\/70680"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/70354"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=10027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=10027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=10027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}