FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
in Python Programming by Goeduhub's Expert (3.1k points)
Python Interview Questions and answers

2 Answers

0 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
Best answer

Question 32: Write a Python program to compute the square of first n Fibonacci numbers, using map function and generate a list of the numbers.

Answer:  In mathematics, the Fibonacci numbers, commonly denoted Fn, where n is number of terms. F1, F2, F3.....Fn.

First and second terms of a fibonacci series are fixed and formula for next terms given below. 

First and second term :

{\displaystyle F_{0}=0,\quad F_{1}=1,}

 and Formula for next terms 

{\displaystyle F_{n}=F_{n-1}+F_{n-2}}

for n> 1

The beginning of the sequence is thus:

{\displaystyle 0,\;1,\;1,\;2,\;3,\;5,\;8,\;13,\;21,\;34,\;55,\;89,\;144,\;\ldots }

 Source : Wikipedia 

how to program fibonacci in python and square of fibonacci series 

#displaying fibonacci series 

number_of_terms = int(input("enter n terms"))

n1, n2 = 0, 1

count = 0


while count < number_of_terms:

  nth = n1 + n2


  n1 = n2

  n2 = nth

  count += 1

print("fibonacci series", fib)

#printing sqaure of fibonacci series using map function 

Sq=lambda n: n*n

map_obj= map(Sq, fib)


print("sequare of fibonacci series", sq_fib)

Output :

fibonacci map

Question 33: How to scrap data from a website in python ?

Answer: Web scraping:  As we know nowadays internet is a storage of vast data. Off course we don't need all the data and in such situation, we  need only the data that meets our need. 

For example form a shopping website you want to buy a mobile phone then you can just write a few line python code and can extract the data for mobiles only (price, model etc...).

Now you can ask a question here that the websites already give us filter options then why we need web scraping ?.

In this case filter has no limit , meaning you can add filters to make your search simple. 

And you can also use web scraped data to do python programming. As we already know if we want to use data in programming it should be in structure form, If not we have to make it in structure form. 

You can also use API of website to extract data for your use but the problem is not all websites have API. In such case you can use web scraping to extract data from a web page. 

How to extract data from a web page using python ? 

For this it will be helpful to you if you have knowledge of basic html, and python beautiful soup library

Click here to see a practical example beautiful soup.

Question 34: Write a Python program to remove lowercase substrings from a given string.

Answer:  We can do this problem by using for loop and conditions. But what if we a large string, in that case we might have problem in traversing.

Python Regular Expression Library  is basically used in such cases. It is used to search, extract and update a sequence of character.

Regular expressions also called REs, or regexes, or regex patterns made available through the re module in Python.

Python Regular Expression (re module) full tutorial (Concepts and Examples)

#regular expression in python

import re


lower_case= re.sub('[a-z]', ' ',string)





Q.35. What is type conversion in Python?

Answer:- Type Conversion is the conversion of object from one data type to another data type. Python has two types of type conversion.

  • Implicit Type Conversion
  • Explicit Type Conversion

Implicit Type Conversion- Python automatically converts from one data type to another data type without user intervention.Example-



print(type(A), type(B))   // here data type of A is integer and B is float



Note- Here data type of C is float, python automatically converts from smaller data type to larger data type to save data loss. This is example of implicit Type Conversion.

Explicit Type Conversion- Python have certain functions to convert from one data type to another. List of functions-

int() – converts any data type into integer type

float() – converts any data type into float type

ord() – converts characters into integer

hex() – converts integers to hexadecimal

oct() – converts integer to octal

tuple() – This function is used to convert to a tuple.

set() – This function returns the type after converting to set.

list() – This function is used to convert any data type to a list type.

dict() – This function is used to convert a tuple of order (key,value) into a dictionary.

str() – Used to convert integer into a string.

Q.36. What are the supported standard data types in Python?

Answer:- Here is the list of most commonly used built-in types that Python supports:

Immutable built-in datatypes of Python

  • Numbers
  • Strings
  • Tuples

Mutable built-in datatypes of Python

  • List
  • Dictionaries
  • Sets

Q.37. What is Indentation in Python and Why is Python Indentation Important?

Answer:- It is very important to understand indentation in Python if you want to run your program without any error, otherwise you will get indentation error when you run the program.

Indentation specifies a block of code. All code within loops, classes, functions, etc is specified within an indented block.

In languages like C, C++, Java, we use curly braces { } to indicate the start and end of a block of code. In Python to give indentation after colon is , after pressing enter key either you give some space (Key) or you give tab (Key).

In simple, all the statements with the same distance (space) to the right, belong to the same block. In other words, statements belonging to a block will necessarily start from the same vertical line. You can imagine it this way.

python indentation

Q.38. How would you define a block in Python?

Answer:- 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.

Q.39. What is the difference between .py and .pyc files in Python?


  • .py files contain the source code of a program. Whereas, .pyc file contains the bytecode of your program. We get bytecode after compilation of .py file (source code). A .pyc is not created for your main program file that you execute (only for imported modules).
  • Before executing a python program python interpreter checks for the compiled files. If the file is present, the virtual machine executes it. If not found, it checks for .py file. If found, compiles it to .pyc file and then python virtual machine executes it.
  • Having .pyc file saves you the compilation time.

Q.40.  How do you invoke the Python interpreter for interactive use?


On Windows, bring up the command prompt and type "py", or start an interactive Python session by selecting "Python (command line)", "IDLE", or similar program from the task bar / app menu.

On macOS or linux, open a terminal and simply type "python".

Q.41.  Is Python fully object oriented?

Answer:- Python does follow an object-oriented programming paradigm and has all the basic OOPs concepts such as inheritance, polymorphism, and more, with the exception of access specifiers. Python doesn’t support strong encapsulation (adding a private keyword before data members). Although, it has a convention that can be used for data hiding, i.e., prefixing a data member with two underscores.


0 like 0 dislike
by Goeduhub's Expert (9.3k points)

Q.42. Do we need to declare variables with data types in Python?

 Answer:- No. Python is a dynamically typed language, i.e., Python Interpreter automatically identifies the data type of a variable based on the type of value assigned to the variable.

Q.43. What is the difference between lists and tuples?


Lists are mutable, i.e., they can be edited.

Tuples are immutable (they are lists that cannot be edited).

Lists are usually slower than tuples.

Tuples are faster than lists.


 list_1 = [100, ‘Goeduhub’, 200]


 tup_1 = (10, ‘Goeduhub’ , 20)

Q.44. Is there a switch or case statement in Python? If not then what is the reason for the same?

Answer:-  Python does not have a switch or case statement.

We can use the powerful dictionary mappings  to implement switch statement , also known as associative arrays, that provide simple one-to-one key-value mappings.
Here is a example-
# Switcher is dictionary data type here or a dictionary which contains key-values
def xyz(x):
  switcher = {
        0: "zero",
        1: "one",
        2: "two",
  return switcher.get(x, "nothing")
  # get() method of dictionary data type which takes maximum of two parameters  
  #key - key to be searched in the dictionary
  #value (optional) - Value to be returned if the key is not found. The default value is None.

n=int(input("enter the choice"))

Q.45. What is a map function in Python?

Answer:- The map() function in Python has two parameters, function and iterable. The map() function takes a function as an argument and then applies that function to all the elements of an iterable, passed to it as another argument. It returns an object list of results.

 For e.g. def calculateSq(n):

 return n*n numbers = (2, 3, 4, 5)

 result = map( calculateSq, numbers)


Is python numpy better than lists?

Q.46. Is python numpy better than lists?

Answer:- We use python numpy array instead of a list because of the below three reasons:

Less Memory



Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs


About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © Social::   |  | 


Free Online Directory