{"id":9685,"date":"2020-01-29T07:34:38","date_gmt":"2020-01-29T07:34:38","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=9685"},"modified":"2021-11-13T06:05:56","modified_gmt":"2021-11-13T06:05:56","slug":"python-interview-questions-and-answer-part-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/python-interview-questions-and-answer-part-2\/","title":{"rendered":"Python Interview Questions and Answer Part \u2013 2"},"content":{"rendered":"\n<p><strong>Which argument would you use in a Python function to obtain a dictionary of all the named arguments passed?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Keyword Arguments (**kwargs) (Ans)<\/strong><\/li><li>*args<\/li><li>The NoneType argument<\/li><li>Regular function arguments<\/li><\/ul>\n\n\n\n<p><strong>To create a virtual environment, you use the following command:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>virtualenv-create<\/li><li>virtualenvironment<\/li><li>virtualenv (Ans)<\/li><li>virtual-env<\/li><\/ul>\n\n\n\n<p><strong>A nested function can access its parent&#8217;s function variable and use that data within it.<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>True (Ans)<\/strong><\/li><li>False<\/li><\/ul>\n\n\n\n<p><strong>To install a Python package using pip, you use:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>pip install (Ans)<\/strong><\/li><li>pip get<\/li><li>pip add<\/li><li>pip uninstall<\/li><\/ul>\n\n\n\n<p><strong>Flask is used:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>as a Python utility library.<\/li><li><strong>as a Web microframework. (Ans)<\/strong><\/li><li>as a general purpose Python library.<\/li><li>Similarly to how pip is used.<\/li><\/ul>\n\n\n\n<p><strong>One of the Python packages used for creating executable files out of Python code is called:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>PyInstaller (Ans)<\/strong><\/li><li>PyMaker<\/li><li>Flask<\/li><li>Django<\/li><\/ul>\n\n\n\n<p><strong>Python requires us to declare types such as int, string, and char[] before declaring a variable<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>True<\/li><li><strong>False (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>In order to group multiple objects in one variable, you use:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>array<\/li><li><strong>list (Ans)<\/strong><\/li><li>collection<\/li><li>dictionary<\/li><\/ul>\n\n\n\n<p><strong>When creating two instances of the same class, those two instances will share all the data automatically<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>True<\/li><li><strong>False (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>In Python, a class can inherit from exactly this number of parent classes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1<\/li><li><strong>Many (Ans)<\/strong><\/li><li>None<\/li><li>3<\/li><\/ul>\n\n\n\n<p><strong>To help debug your application, you can set something called a:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Stop point<\/li><li>Pause<\/li><li>Resume point<\/li><li><strong>Breakpoint (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>The constructor method in Python classes looks similar to this<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>def initialize(self):<\/li><li>def constructor():<\/li><li><strong>def init(self): (Ans)<\/strong><\/li><li>There is no constructor method in Python classes<\/li><\/ul>\n\n\n\n<p><strong>What is the result of the following code?<\/strong><\/p>\n\n\n\n<p>names = [&#8220;Jonathan&#8221;, &#8220;Bo&#8221;, &#8220;Layla&#8221;, &#8220;Kristin&#8221;]<br>\nfor name in names:<br>\n    if name == &#8220;Bo&#8221;:<br>\n        print(&#8220;Found the instructor!&#8221;)<br>\n        break<br>\n    print(&#8220;{0} is not the instructor&#8221;.format(name))<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>It will print &#8220;Jonathan is not the instructor&#8221;, after which it will print &#8220;Found the instructor&#8221; and then stop the for loop. (Ans)<\/strong><\/li><li>It will print &#8220;Jonathan is not the instructor&#8221;, after which it will print &#8220;Found the instructor&#8221; and continue to print the rest of the list.<\/li><li>It will print &#8220;Kristin is not the instructor&#8221;, after which it will print &#8220;Found the instructor&#8221; and stop the for loop.<\/li><li>It will print all the names from the list.<\/li><\/ul>\n\n\n\n<p><strong>Which one of the following is a valid dictionary?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>All of them (Ans)<\/strong><\/li><li>{ &#8220;name&#8221;: &#8220;Mark&#8221; }<\/li><li>{ &#8220;name&#8221;: &#8220;Mark&#8221;, &#8220;student_Id&#8221;: 16135 }<\/li><li>{ &#8220;name&#8221;: &#8220;Bo&#8221;, &#8220;student_id&#8221;: 42671, instructor: True }<\/li><\/ul>\n\n\n\n<p><strong>What keyword do we use in a function when we want to return the data to the function caller?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>respond<\/li><li>give_back<\/li><li>print()<\/li><li>reply<\/li><li><strong>return (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Class attributes do share their value across different instances of that class.<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>True, but only if the class attribute name has a dash.<\/li><li>False<\/li><li>False, except when the class attribute name starts with a capital letter.<\/li><li><strong>True (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Which function in unittest will run all of your tests?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>unittest.execute()<\/li><li>unittest.run()<\/li><li><strong>unittest.main() (Ans)<\/strong><\/li><li>unittest.generate_report()<\/li><\/ul>\n\n\n\n<p><strong>What is one way to create a list from another sequence?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>a with-statement<\/li><li><strong>the list constructor (Ans)<\/strong><\/li><li>the split() method<\/li><li>the make_string() function<\/li><\/ul>\n\n\n\n<p><strong>What does PDB&#8217;s where command do?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Prints the current call stack (Ans)<\/strong><\/li><li>Shows where an attribute was initially defined<\/li><li>Prints directory containing the current source file<\/li><li>Prints the current timezone<\/li><\/ul>\n\n\n\n<p><strong>When converting a float to an integer with the int() constructor in which direction is rounding?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Towards zero (Ans)<\/strong><\/li><li>Away from zero<\/li><li>Towards the nearest integer<\/li><li>Towards positive infinity<br> E. Towards negative infinity<\/li><\/ul>\n\n\n\n<p><strong>What is one way in which exceptions are superior to error codes?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>They are faster.<\/li><li><strong>They cannot be easily ignored. (Ans)<\/strong><\/li><li>They aren&#8217;t part of a function&#8217;s API.<\/li><li>Python doesn&#8217;t support error codes.<\/li><\/ul>\n\n\n\n<p><strong>What does Python&#8217;s id() function return?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>A unique identifier for an object (Ans)<\/strong><\/li><li>The version of the Python runtime<\/li><li>The order in which an object was created<\/li><li>The name of an object<\/li><\/ul>\n\n\n\n<p><strong>Are functions also objects in Python?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Yes (Ans)<\/strong><\/li><li>Only if you declare them so explicitly<\/li><li>Module-level functions are, but not instance methods<\/li><li>No<\/li><\/ul>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_56809\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_44344\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_56809\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Which argument would you use in a Python function to obtain a dictionary of all the named arguments passed? Keyword Arguments (**kwargs) (Ans) *args The NoneType argument Regular function arguments To create a virtual environment, you use the following command: virtualenv-create virtualenvironment virtualenv (Ans) virtual-env A nested function can access its parent&#8217;s function variable and&#8230;<\/p>\n","protected":false},"author":1,"featured_media":9804,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[499],"tags":[641,766,176,482],"class_list":["post-9685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-programming-scripting-languages","tag-answers","tag-interview","tag-python","tag-questions"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9685"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9685\/revisions"}],"predecessor-version":[{"id":24985,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9685\/revisions\/24985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/9804"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}