Call us Today ! +91 72590 78678 | info@xilytica.com
  • No products in the cart.

Python Interview Questions

Interview Question in Python for
Data Science

Basics

Q1. Print the output for below expressions

1) 2 + 4.15

2) 3.15 – 4.05

3) 2 + 9.5 – 11

4) 2.17 * 3.15

5) 3 + 6 * 2

6) 22 / 7.0

7) 22 % 7

8) 2 ** 4

9) 2 ** 7.5

10) 9 ** 1/2

11) 9 ** (1/2)

 

Q2. Print the output for below expression

    y = 7

    y = y+y**y%y

    y = y+y**(y%y)

 

Q3. Follow the instructions  –  

  1. Create an integer type variable ron_day_salary,  then assign 100 to it
  2. Create another variable work_days and assign 5 to it
  3.  Create another variable ron_week_sal & it should be equal to ron_day_salary * work_days  (* mean multiplication)
  4. Create expanse_per_day variable and assign 15.90 to it
  5. Multiply expanse_per_day variable with 7 and assign an output to expanse_per_week variable
  6. Finally create variable ron_week_save = ron_week_sal – expanse_per_week
  7. Find out the data type for each of the variables created above

 

Q4. Follow the instructions –   

  1. Create String type variable my_fav_car and assign any name of the car to it
  2. Create another string type variable car_color & assign any color to it
  3. Create string type variable car_milage & assign 29 mpg  to it
  4. Create string type variable with car_price and assign 300,000
  5. Create string type variable car_number & assign 10102 to it

Q1. 

my_line_str = ‘This is line number 1. This is line number 2. This is line number 3. This is line number 4’

 

  1. Using newline escape sequence print string after a full stop to be in the next line.
  2. Using triple quote print string after a full stop to be in the next line.

 

Hint – output should be – 

 

This is line number 1

This is line number 2

This is line number 3

This is line number 4

Q2.  Follow the instructions and print the desired output – 

 

  1. Calculate the length of

alpha = ‘a,b,c,d,e,f,g,h,i,j,k’

  1. Using slicing select –
  2. ‘a,b,c’
  3. ‘d,e,f’
  4. ‘i,j,k’
  5. ‘abcdefghijk’

Q3.  my_str_a = ‘Was it a car or a cat I saw’

 my_str_b = ‘Borrow or rob’

  1. Print the above strings in backward.
  2. Concatenate the backward strings with a space between the two strings
  3. Concatenate the above strings with the 2nd string on the next line.

Q4. my_grt = ‘good day’

Manipulate the above string so that output is ‘Good day’

 

Q5. data = ‘Data! Data! Data! can not make bricks without clay’

  1. Find out the Index of bricks
  2. Manipulate the above string so that output display only aa 
  3. Manipulate the above string to display only alternate characters
  4. Display above string in backward

Q6. Create a list with a minimum length of 12 &  that has below following datatypes & data structures

  1. integers
  2. Floats
  3. Boolean
  4. list
  5. string

Q7. For below list print each element in next line

cars = [‘Ford’,’Tata’,’Lexus’,’Porsche’,’Mustang’]

Q8. my_list_mix = [1,2.0,’Mon’,True,(2,3),{‘name’:’Bill’},{‘a’,’b’}]

  1. Find out the length of the list 
  2. Print out each element of the list separately
  3. Print out the type of each element the separately
  4. Print out the type of each element in the next line 

Hint – have to use next line escape sequence in print statement

Have to convert all elements of the list into string at the time of print and concatenation.

like – str(my_list_mix[0])

Q9.my_list1 = [‘O’,’1′,’O’,’1′,’O’,’1′,’O’,’1′,’O’]

my_list2 = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0]

  1. For list my_list1 using slicing  print only ‘O’
  2. For list my_lis21 using slicing  print only 1
  3. What are immutable objects in python? Out of string & list which one is immutable. Explain with example

Q1.Create a tuple that contains the first five prime numbers.

Q2.Which of the following is a Python tuple?

  1. a) [1, 2, 3]
  2. b) (1, 2, 3)
  3. c) {1, 2, 3}
  4. d) {}

Q3. Create an empty tuple.

Q4.Create a tuple with mixed data types.

Q5.What will be the output of the following Python code?

tup = (1,2,3,4)

tup[1:-1]

Q6.What will be the output of the following Python code?

Explain the output 

tup1 = (1,2,3,4)

tup2 = (1,2,4,3)

  1. a) True
  2. b) False
  3. c) Error
  4. d) None

 

Q7.Access value 20 from the following tuple

tupmix = (“Orange”, [10, 20, 30], (5, 15, 25))

 

Q8.Unpack the following tuple into 4 variables

mytuple = (10, 20, 30, 40 ) 

 

Q9.Swap the following two tuples in one step ( Use tuple unpacking )

tup1 = (10,20)

tup2 = (1,2)

 

Q10.Modify the first item (2) of a list inside a following tuple to 22

tuple1 = (1, [2, 3], 4, 5)

 

Q11.Create a set that has values 1,2,3

 

Q12.Create an empty set and empty dictionary

 

Q13.Create a mixed data type set 

Find out for which data types you get an error

 

Q14.mystr = ‘abcdefghijklmnopqrstuvwxyz’

  1. Transform it above created mystr variable into list type variable and print the created variable
  2. Transform it above created mystr variable into tuple type variable and print the created variable
  3. Transform it above created mystr variable into set type variable and print the created variable

Q15.Execute the below-highlighted statement to generate a random number 

Import random

Create variables a  & b by executing below expressions

  1. a = random.int(1,100)
  2. b = random.int(1,1000)
  3. c = random.random()

For above created variables what will be the output for below expressions
1. a == b

  1. a < = b
  2. a  != b
  3. a*c <b and b*c<a
  4. a*b < a**a or a*b <b**b
  5. a*b != c*c

Q16. 

a = ‘hi’

b = ‘hi’

c = ‘hi there’

d = ‘hi there’

For the four created variables what will be the output for the below expressions

  1. a is b
  2. a is not b
  3. c is d
  4. c is not d
  5. a == b
  6. c== d

Q17.my_num = [1,2,3,4,5]

Using membership operator check if 4 is a member of the sequence my_num

Q18.my_dict = {

    ‘count’:[1,2,3,4],

    (‘a’,’b’):[1,2,3]

}

Using membership operator check if (‘a’,’b’) is a member of the dictionary my_dict

Q19.Using If statement print if the variable is odd or even

 

Q20.Using If & Else statements print Even if the variable is even, else print odd

 

Q21.Using If, Elif & Else statements print if the variable is completely divisible by 2 or by 3 or not by divisible by 2 and 3. 

Print accordingly

Hint – completely divisible means no remainder.

Q22.a = random.randint(1,100)

b = random.randint(1,100)

Using If, Elif & Else statement print greater of two above created variables. Print both the name of the variable and value of the variable

Q23.table_cost = random.randint(1,100)

If the value of the table_cost variable is between 10 & 40,  subtract 10% of the table_cost from table_cost variable and print the final output. Else if value of the table_cost variable is between 40 and 80, subtract 50% of the table_cost from table_cost variable and print the final output. Else if value of the table_cost variable is equal or more than 80, subtract 100% of the table_cost from the table_cost and print

“The table is free”

 

Q24.A school has the following rules for grading system:

  1. Below 25 – F
  2. 25 to 45 – E
  3. 45 to 50 – D
  4. 50 to 60 – C
  5. 60 to 80 – B
  6. Above 80 – A

Marks =  random.randint(10,90)

Print the corresponding grades

 

Q25. a = random.randint(1,100)

b = random.randint(1,100)

c = random.randint(1,100)

 

Find out the smallest and largest of the number

Functions

Q1. Write a function that print ‘Hello World’

Q2. Write a function that returns ‘Hello World’

Q3. Write a function that takes in a boolean as in parameter. If the boolean is True print ‘you have passed True as in parameter’. IF the boolean  is False print ‘you have entered a False as in parameter’

Q4. Write a function that takes in a number as in parameter. If the number is even, print ‘you have passed an even number’. IF the number is odd print ‘you have entered an odd number’

Q5. Write a function that takes in two numbers. Print their sum and multiplication.

Q6. Write a function that takes in two numbers. Return their sum and multiplication as a tuple. 

Q7. Write a function that takes 3 numbers and returns the biggest number.

Q8. Write a function that calculates the length of flexibility in parameters.

Q9.Write a function that calculates the type of flexible in parameters.

Q10.Write a function that returns the datatype of in parameter. If the in a parameter is float system return ‘In parameter is of Float Data Type’. IF a parameter is boolean then it should return in a parameter is of type Bool etc.

Q11.Write a function that changes the case (upper character to lower and vice-versa) of the 1st and 7th character of the string. The function should also check whether the string has a length 7 or more. If the length of a string is less than 7 then the function should change the case of 1st and last character of the in parameter.

Q12. Explain the .join method in detail by giving examples

Q13.Write a function that removes the vowels from the input string.

Q14.Write a function that calculates the number of upper & lower characters in the string.

Q15.Write a function that removes the duplicates from the list.




close
open