{"id":2730,"date":"2023-12-18T07:35:00","date_gmt":"2023-12-18T07:35:00","guid":{"rendered":"https:\/\/www.kaashivinfotech.com\/blog\/?p=2730"},"modified":"2023-12-18T10:18:34","modified_gmt":"2023-12-18T10:18:34","slug":"experience-python-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.kaashivinfotech.com\/blog\/experience-python-interview-questions-and-answers\/","title":{"rendered":"Experience Python Interview Questions and Answers"},"content":{"rendered":"<p>Python is a general-purpose, dynamic, high-level, and interpreted programming language. It supports Object Oriented programming approach to develop applications. It is simple and easy to learn and provides lots of high-level data structures.<\/p>\n<p>&#8220;Mastering Python Interviews&#8221; is your comprehensive companion, providing the knowledge and confidence needed to showcase your Python prowess and stand out in today&#8217;s competitive job market. Whether you&#8217;re gearing up for your first Python interview or aiming for a career advancement, this guide is tailored to elevate your interview performance and set you on the path to success.<\/p>\n<p>Python is an easy-to-learn yet powerful and versatile scripting language, which makes it attractive for Application Development.<\/p>\n<p>With its interpreted nature, Python\u2019s syntax and dynamic typing make it an ideal language for scripting and rapid application development.<\/p>\n<p>Python supports multiple programming patterns, including object-oriented, imperative, and functional or procedural programming styles.<\/p>\n<p>Python is not intended to work in a particular area, such as web programming. It is a multipurpose programming language because it can be used with web, enterprise, 3D CAD, etc.<\/p>\n<p>We don\u2019t need to use data types to declare variable because it is dynamically typed, so we can write a=10 to assign an integer value in an integer variable.<\/p>\n<style>\/*! elementor - v3.18.0 - 08-12-2023 *\/<br \/>.elementor-heading-title{padding:0;margin:0;line-height:1}.elementor-widget-heading .elementor-heading-title[class*=elementor-size-]>a{color:inherit;font-size:inherit;line-height:inherit}.elementor-widget-heading .elementor-heading-title.elementor-size-small{font-size:15px}.elementor-widget-heading .elementor-heading-title.elementor-size-medium{font-size:19px}.elementor-widget-heading .elementor-heading-title.elementor-size-large{font-size:29px}.elementor-widget-heading .elementor-heading-title.elementor-size-xl{font-size:39px}.elementor-widget-heading .elementor-heading-title.elementor-size-xxl{font-size:59px}<\/style>\n<h2>Experience Python Interview Questions<\/h2>\n<style>\/*! elementor - v3.18.0 - 08-12-2023 *\/<br \/>.elementor-accordion{text-align:left}.elementor-accordion .elementor-accordion-item{border:1px solid #d5d8dc}.elementor-accordion .elementor-accordion-item+.elementor-accordion-item{border-top:none}.elementor-accordion .elementor-tab-title{margin:0;padding:15px 20px;font-weight:700;line-height:1;cursor:pointer;outline:none}.elementor-accordion .elementor-tab-title .elementor-accordion-icon{display:inline-block;width:1.5em}.elementor-accordion .elementor-tab-title .elementor-accordion-icon svg{width:1em;height:1em}.elementor-accordion .elementor-tab-title .elementor-accordion-icon.elementor-accordion-icon-right{float:right;text-align:right}.elementor-accordion .elementor-tab-title .elementor-accordion-icon.elementor-accordion-icon-left{float:left;text-align:left}.elementor-accordion .elementor-tab-title .elementor-accordion-icon .elementor-accordion-icon-closed{display:block}.elementor-accordion .elementor-tab-title .elementor-accordion-icon .elementor-accordion-icon-opened,.elementor-accordion .elementor-tab-title.elementor-active .elementor-accordion-icon-closed{display:none}.elementor-accordion .elementor-tab-title.elementor-active .elementor-accordion-icon-opened{display:block}.elementor-accordion .elementor-tab-content{display:none;padding:15px 20px;border-top:1px solid #d5d8dc}@media (max-width:767px){.elementor-accordion .elementor-tab-title{padding:12px 15px}.elementor-accordion .elementor-tab-title .elementor-accordion-icon{width:1.2em}.elementor-accordion .elementor-tab-content{padding:7px 15px}}.e-con-inner>.elementor-widget-accordion,.e-con>.elementor-widget-accordion{width:var(--container-widget-width);--flex-grow:var(--container-widget-flex-grow)}<\/style>\n<p><a tabindex=\"0\">1. What is Polymorphism in Python ?<\/a><\/p>\n<p>Polymorphism means the ability to take multiple forms. So, for instance, if the parent class has a method named ABC then the child class also can have a method with the same name ABC having its own parameters and variables. Python allows polymorphism.<\/p>\n<p><a tabindex=\"0\">2. Define encapsulation in Python ?<\/a><\/p>\n<p>Encapsulation means binding the code and the data together. A Python class in an example of encapsulation.<\/p>\n<p><a tabindex=\"0\">3. How do you do data abstraction in Python ?<\/a><\/p>\n<p>Data Abstraction is providing only the required details and hiding the implementation from the world. It can be achieved in Python by using interfaces and abstract classes.<\/p>\n<p><a tabindex=\"0\">4.Does python make use of access specifiers ?<\/a><\/p>\n<p>Python does not deprive access to an instance variable or function. Python lays down the concept of prefixing the name of the variable, function or method with a single or double underscore to imitate the behavior\u00a0of protected and private access specifiers.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">5.How to create an empty class in Python ? <\/a><\/p>\n<p>An empty class is a class that does not have any code defined within its block. It can be created using the\u00a0<em>pass\u00a0<\/em>keyword. However, you can create objects of this class outside the class itself. IN PYTHON THE PASS command does nothing when its executed. it\u2019s a null statement.<\/p>\n<p><strong>For example-<\/strong><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\tclass a:\n  pass\nobj=a()\nobj.name=&quot;xyz&quot;\nprint(&quot;Name = &quot;,obj.name)<\/code><\/pre>\n<p><strong>Output:\u00a0<\/strong><\/p>\n<p>Name =\u00a0 xyz<\/p>\n<p><a tabindex=\"0\">6.What does an object() do ?<\/a><\/p>\n<p>It returns a featureless object that is a base for all classes. Also, it does not take any parameters.<\/p>\n<p>Next, let us have a look at some Basic Python Programs in these Python Interview Questions.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">7.. Write a program in Python to execute the Bubble sort algorithm ?<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\tdef bs(a):\n# a = name of list\n   b=len(a)-1nbsp; \n# minus 1 because we always compare 2 adjacent values\n   for x in range(b):\n        for y in range(b-x):\n              a[y]=a[y+1]\n   \n   a=[32,5,3,6,7,54,87]\n   bs(a)<\/code><\/pre>\n<p><strong>Output:\u00a0\u00a0<\/strong>[3, 5, 6, 7, 32, 54, 87]<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">8.Write a program in Python to produce Star triangle ?<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\tdef pyfunc(r):\n    for x in range(r):\n        print(&#039; &#039;*(r-x-1)+&#039;*&#039;*(2*x+1))    \npyfunc(9)<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>*<\/p>\n<p>***<\/p>\n<p>*****<\/p>\n<p>*******<\/p>\n<p>*********<\/p>\n<p>***********<\/p>\n<p>*************<\/p>\n<p>***************<\/p>\n<p>*****************<\/p>\n<p><a tabindex=\"0\">9.Write a program to produce Fibonacci series in Python ?<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\t# Enter number of terms needednbsp;#0,1,1,2,3,5....\na=int(input(&quot;Enter the terms&quot;))\nf=0;#first element of series\ns=1#second element of series\nif a=0:\n   print(&quot;The requested series is&quot;,f)\nelse:\n  print(f,s,end=&quot; &quot;)\n   for x in range(2,a): \n         print(next,end=&quot; &quot;)\n         f=s\n         s=next<\/code><\/pre>\n<p><strong>Output:<\/strong>\u00a0Enter the terms 5 0 1 1 2 3<\/p>\n<p><a tabindex=\"0\">10.Write a program in Python to check if a number is prime ?<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\ta=int(input(&quot;enter number&quot;))\nif a=1:\n   for x in range(2,a):\n         if(a%x)==0:\n          print(&quot;not prime&quot;)\n   break\n   else:\n      print(&quot;Prime&quot;)\nelse:\n   print(&quot;not prime&quot;)<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>enter number 3<\/p>\n<p>Prime<\/p>\n<p><a tabindex=\"0\">11.Write a program in Python to check if a sequence is a Palindrome ?<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\ta=input(&quot;enter sequence&quot;)\nb=a[::-1]\nif a==b:\n  print(&quot;palindrome&quot;)\nelse:\n  print(&quot;Not a Palindrome&quot;)<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>enter sequence 323 palindrome<\/p>\n<p><a tabindex=\"0\">12.Write a one-liner that will count the number of capital letters in a file. Your code should work even if the file is too big to fit in memory ?<\/a><\/p>\n<p>Let us first write a multiple line solution and then convert it to one-liner code.<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\twith open(SOME_LARGE_FILE) as fh:\ncount = 0\ntext = fh.read()\nfor character in text:\n    if character.isupper():\ncount += 1<\/code><\/pre>\n<p>We will now try to transform this into a single line.<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\tcount sum(1 for line in fh for character in line if character.isupper())<\/code><\/pre>\n<p><a tabindex=\"0\">13.The following code can be used to sort a list in Python:<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\tlist = [&quot;1&quot;, &quot;4&quot;, &quot;0&quot;, &quot;6&quot;, &quot;9&quot;]\nlist = [int(i) for i in list]\nlist.sort()\nprint (list)<\/code><\/pre>\n<p><a tabindex=\"0\">14.Looking at the below code, write down the final values of A0, A1, \u2026An ?<\/a><\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\tA0 = dict(zip((&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;,&#039;e&#039;),(1,2,3,4,5)))\nA1 = range(10)A2 = sorted([i for i in A1 if i in A0])\nA3 = sorted([A0[s] for s in A0])\nA4 = [i for i in A1 if i in A3]\nA5 = {i:i*i for i in A1}\nA6 = [[i,i*i] for i in A1]\nprint(A0,A1,A2,A3,A4,A5,A6)<\/code><\/pre>\n<p>The following will be the final outputs of A0, A1, \u2026 A6<\/p>\n<p>A0 = {\u2018a\u2019: 1, \u2018c\u2019: 3, \u2018b\u2019: 2, \u2018e\u2019: 5, \u2018d\u2019: 4} # the order may vary<\/p>\n<p>A1 = range(0, 10)<\/p>\n<p>A2 = []<\/p>\n<p>A3 = [1, 2, 3, 4, 5]<\/p>\n<p>A4 = [1, 2, 3, 4, 5]<\/p>\n<p>A5 = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}<\/p>\n<p>A6 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]<\/p>\n<p>Next, in this Python Interview Questions let\u2019s have a look at some Python Libraries<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">15.Explain what Flask is and its benefits ?<\/a><\/p>\n<p>Flask is a web microframework for Python based on \u201cWerkzeug, Jinja2 and good intentions\u201d BSD license. Werkzeug and Jinja2 are two of their dependencies. This means it will have little to no dependencies on external libraries.\u00a0 It makes the framework light while there is a little dependency to update and fewer security bugs.<\/p>\n<p>A session basically allows you to remember information from one request to another. In a flask, a session uses a signed cookie so the user can look at the session contents and modify them. The user can modify the session if only it has the secret key Flask.secret_key.<\/p>\n<p><a tabindex=\"0\">16.Is Django better than Flask ?<\/a><\/p>\n<p>Django and Flask map the URL\u2019s or addresses typed in the web browsers to functions in Python.<\/p>\n<p>Flask is much simpler compared to Django but, Flask does not do a lot for you meaning you will need to specify the details, whereas Django does a lot for you wherein you would not need to do much work.\u00a0<a href=\"https:\/\/www.edureka.co\/blog\/django-tutorial\/\" target=\"_blank\" rel=\"noopener\">Django<\/a>\u00a0consists of prewritten code, which the user will need to analyze whereas Flask gives the users to create their own code, therefore, making it simpler to understand the code. Technically both are equally good and both contain their own pros and cons.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">17.Mention the differences between Django, Pyramid and Flask ?<\/a><\/p>\n<ul>\n<li>Flask is a \u201cmicroframework\u201d primarily build for a small application with simpler requirements. In flask, you have to use external libraries. Flask is ready to use.<\/li>\n<li>Pyramid is built for larger applications. It provides flexibility and lets the developer use the right tools for their project. The developer can choose the database, URL structure, templating style and more. Pyramid is heavy configurable.<\/li>\n<li>Django can also be used for larger applications just like Pyramid. It includes an ORM.<\/li>\n<\/ul>\n<p><a tabindex=\"0\">18.Discuss Django architecture ?<\/a><\/p>\n<p>Django MVT Pattern:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Picture1-300x52.png\" alt=\"\" width=\"361\" height=\"62\" \/><\/p>\n<p><strong>Figure:<\/strong>\u00a0<strong>\u00a0<\/strong><em>Python Interview Questions \u2013 Django Architecture<\/em><\/p>\n<p>The developer provides the Model, the view and the template then just maps it to a URL and Django does the magic to serve it to the user.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">19.Explain how you can set up the Database in Django ?<\/a><\/p>\n<p>You can use the command edit mysite\/setting.py, it is a normal python module with module level representing Django settings.<\/p>\n<p>Django uses SQLite by default; it is easy for Django users as such it won\u2019t require any other type of installation. In the case your database choice is different that you have to the following keys in the\u00a0DATABASE \u2018default\u2019\u00a0item to match your database connection settings.<\/p>\n<ul>\n<li><strong>Engines<\/strong>: you can change the database by using \u2018django.db.backends.sqlite3\u2019 , \u2018django.db.backeneds.mysql\u2019, \u2018django.db.backends.postgresql_psycopg2\u2019, \u2018django.db.backends.oracle\u2019 and so on<\/li>\n<li><strong>Name<\/strong>: The name of your database. In the case if you are using SQLite as your database, in that case, database will be a file on your computer, Name should be a full absolute path, including the file name of that file.<\/li>\n<li>If you are not choosing SQLite as your database then settings like Password, Host, User, etc. must be added.<\/li>\n<\/ul>\n<p>Django uses SQLite as a default database, it stores data as a single file in the filesystem. If you do have a database server\u2014PostgreSQL, MySQL, Oracle, MSSQL\u2014and want to use it rather than SQLite, then use your database\u2019s administration tools to create a new database for your Django project. Either way, with your (empty) database in place, all that remains is to tell Django how to use it. This is where your project\u2019s settings.py file comes in.<\/p>\n<p>We will add the following lines of code to the\u00a0<em>setting.py<\/em>\u00a0file:<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\tDATABASES = {\n     &#039;default&#039;: {\n          &#039;ENGINE&#039; : &#039;django.db.backends.sqlite3&#039;,\n          &#039;NAME&#039; : os.path.join(BASE_DIR, &#039;db.sqlite3&#039;),\n     }\n}<\/code><\/pre>\n<p><a tabindex=\"0\">20.Give an example how you can write a VIEW in Django ?<\/a><\/p>\n<p>This is how we can use write a view in Django:<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\tfrom django.http import HttpResponse\nimport datetime\n \ndef Current_datetime(request):\n     now = datetime.datetime.now()\n     html = &quot;It is now %s\/body\/html % now\n     return HttpResponse(html)<\/code><\/pre>\n<p><em>Returns the current date and time, as an HTML document<\/em><\/p>\n<p><a tabindex=\"0\">21.Mention what the Django templates consist of ?<\/a><\/p>\n<p>The template is a simple text file.\u00a0 It can create any text-based format like XML, CSV, HTML, etc.\u00a0 A template contains variables that get replaced with values when the template is evaluated and tags (% tag %) that control the logic of the template.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Picture2-300x50.png\" alt=\"\" width=\"354\" height=\"59\" \/><\/p>\n<p><strong>Figure:\u00a0<\/strong><em>Python Interview Questions \u2013 Django Template<\/em><\/p>\n<p><a tabindex=\"0\">22.Explain the use of session in Django framework ?<\/a><\/p>\n<p>Django provides a session that lets you store and retrieve data on a per-site-visitor basis. Django abstracts the process of sending and receiving cookies, by placing a session ID cookie on the client side, and storing all the related data on the server side.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Picture3-300x59.png\" alt=\"\" width=\"360\" height=\"71\" \/><\/p>\n<p><strong>Figure:\u00a0<\/strong><em>Python Interview Questions \u2013 Django Framework<\/em><\/p>\n<p>So the data itself is not stored client side. This is nice from a security perspective.<\/p>\n<p><a tabindex=\"0\">23.List out the inheritance styles in Django ?<\/a><\/p>\n<p>In Django, there are three possible inheritance styles:<\/p>\n<ol>\n<li>Abstract Base Classes: This style is used when you only want parent\u2019s class to hold information that you don\u2019t want to type out for each child model.<\/li>\n<li>Multi-table Inheritance: This style is used If you are sub-classing an existing model and need each model to have its own database table.<\/li>\n<li>Proxy models:\u00a0You can use this model, If you only want to modify the Python level behavior of the model, without changing the model\u2019s fields.<\/li>\n<\/ol>\n<p>Next in this Python Interview Question blog, let\u2019s have a look at questions related to Web Scraping.<\/p>\n<p><a tabindex=\"0\">24.How To Save An Image Locally Using Python Whose URL Address I Already Know ?<\/a><\/p>\n<p>We will use the following code to save an image locally from an URL address<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\timport urllib.request\nurllib.request.urlretrieve(&quot;URL&quot;, &quot;local-filename.jpg&quot;)<\/code><\/pre>\n<p><a tabindex=\"0\">25.How can you Get the Google cache age of any URL or web page ?<\/a><\/p>\n<p>Use the following URL format:<\/p>\n<p>http:\/\/webcache.googleusercontent.com\/search ?q=cache:URLGOESHERE<\/p>\n<p>Be sure to replace \u201cURLGOESHERE\u201d with the proper web address of the page or site whose cache you want to retrieve and see the time for. For example, to check the Google Webcache age of Kaashiv.com you\u2019d use the following URL:<\/p>\n<p>http:\/\/webcache.googleusercontent.com\/search ?q=cache:Kaashiv.com<\/p>\n<p><a tabindex=\"0\">26.You are required to scrap data from IMDb top 250 movies page. It should only have fields movie name, year, and rating ?<\/a><\/p>\n<p>We will use the following lines of code:<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\tfrom bs4 import BeautifulSoup\n \nimport requests\nimport sys\n \nurl = &#039;&lt;a href=&quot;http:\/\/www.imdb.com\/chart\/top&quot;&gt;http:\/\/www.imdb.com\/chart\/top&lt;\/a&gt;&#039;\nresponse = requests.get(url)\nsoup = BeautifulSoup(response.text)\ntr = soup.findChildren(&quot;tr&quot;)\ntr = iter(tr)\nnext(tr)\n \nfor movie in tr:\ntitle = movie.find(&#039;td&#039;, {&#039;class&#039;: &#039;titleColumn&#039;} ).find(&#039;a&#039;).contents[0]\nyear = movie.find(&#039;td&#039;, {&#039;class&#039;: &#039;titleColumn&#039;} ).find(&#039;span&#039;, {&#039;class&#039;: &#039;secondaryInfo&#039;}).contents[0]\nrating = movie.find(&#039;td&#039;, {&#039;class&#039;: &#039;ratingColumn imdbRating&#039;} ).find(&#039;strong&#039;).contents[0]\nrow = title + &#039; - &#039; + year + &#039; &#039; + &#039; &#039; + rating\n \nprint(row)<\/code><\/pre>\n<p>The above code will help scrap data from IMDb\u2019s top 250 list<\/p>\n<p>Next in this Python Interview Questions blog, let\u2019s have a look at questions related to Data Analysis in Python.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><a tabindex=\"0\">28.What is map function in Python ?<\/a><\/p>\n<p><em>map<\/em>\u00a0function executes the function given as the first argument on all the elements of the iterable given as the second argument. If the function given takes in more than 1 arguments, then many iterables are given. #Follow the link to know more similar functions.<\/p>\n<p><a tabindex=\"0\">29.Is python numpy better than lists ?<\/a><\/p>\n<p>We use python numpy array instead of a list because of the below three reasons:<\/p>\n<ol>\n<li>Less Memory<\/li>\n<li>Fast<\/li>\n<li>Convenient<\/li>\n<\/ol>\n<p>For more information on these parameters, you can refer to this section \u2013\u00a0Numpy Vs List.<\/p>\n<p><a tabindex=\"0\">30.How to get indices of N maximum values in a NumPy array ?<\/a><\/p>\n<p>We can get the indices of N maximum values in a NumPy array using the below code:<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\timport numpy as np\narr = np.array([1, 3, 2, 4, 5])\nprint(arr.argsort()[-3:][::-1])<\/code><\/pre>\n<p>Output<\/p>\n<p>[ 4 3 1 ]<\/p>\n<p><a tabindex=\"0\">31.How do you calculate percentiles with Python\/ NumPy ?<\/a><\/p>\n<p>We can calculate percentiles with the following code<\/p>\n<pre data-start=\"1\" data-line-offset=\"0\"><code class=\"\" data-line=\"\">1\n2\n3\n4\timport numpy as np\na = np.array([1,2,3,4,5])\np = np.percentile(a, 50) #Returns 50th percentile, e.g. median\nprint(p)<\/code><\/pre>\n<p><strong>Output<\/strong>:3<\/p>\n<p><a tabindex=\"0\">32.What is the difference between NumPy and SciPy ?<\/a><\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"255\"><strong>NumPy<\/strong><\/td>\n<td width=\"255\"><strong>SciPy<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"255\">It refers to Numerical python.<\/td>\n<td width=\"255\">It refers to Scientific python.<\/td>\n<\/tr>\n<tr>\n<td width=\"255\">It has fewer new\u00a0scientific computing features.<\/td>\n<td width=\"255\">Most new scientific computing features belong in SciPy.<\/td>\n<\/tr>\n<tr>\n<td width=\"255\">It contains less\u00a0linear algebra functions.<\/td>\n<td width=\"255\">It has more\u00a0fully-featured versions of the linear algebra modules, as well as many other numerical algorithms.<\/td>\n<\/tr>\n<tr>\n<td width=\"255\">NumPy has a faster processing speed.<\/td>\n<td width=\"255\">SciPy on the other hand has slower computational speed.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a tabindex=\"0\">33.How do you make 3D plots\/visualizations using NumPy\/SciPy ?<\/a><\/p>\n<p>Like 2D plotting, 3D graphics is beyond the scope of NumPy and SciPy, but just as in the 2D case, packages exist that integrate with NumPy.\u00a0Matplotlib\u00a0provides basic 3D plotting in the\u00a0mplot3d\u00a0subpackage, whereas\u00a0Mayavi\u00a0provides a wide range of high-quality 3D visualization features, utilizing the powerful\u00a0VTK\u00a0engine.<\/p>\n","protected":false},"excerpt":{"rendered":"Python is a general-purpose, dynamic, high-level, and interpreted programming language. It supports Object Oriented programming approach to develop&hellip;","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[724],"tags":[775,777,770,776,758,761,778,773,774],"class_list":["post-2730","post","type-post","status-publish","format-standard","category-interview-questions","tag-advanced-python-interview-questions-and-answers","tag-python-basic-interview-questions-and-answers","tag-python-coding-interview-questions-and-answers","tag-python-interview-questions-answers","tag-python-interview-questions-and-answers","tag-python-interview-questions-and-answers-for-experienced","tag-python-interview-questions-and-answers-freshers","tag-python-interview-questions-for-experienced","tag-python-pandas-interview-questions-for-experienced","cs-entry"],"_links":{"self":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=2730"}],"version-history":[{"count":6,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2730\/revisions"}],"predecessor-version":[{"id":2775,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2730\/revisions\/2775"}],"wp:attachment":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=2730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=2730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=2730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}