Python Developer Interview Questions

Python Developer Interview Questions

"Python developers are responsible for developing code to build products using the python programming language. In an interview context, expect to be quizzed on your technical skills through different kinds of computing problems or brainteasers. The specific questions you are asked will depend on what type of programming position you are looking for. Try researching a specific discipline such as web development, application development, or system development."

3,109 Python Developer interview questions shared by candidates

Top Interview Questions

Sort: Relevance|Popular|Date
Senior Python Developer was asked...April 23, 2016

For the years 1901 to 2000, count the total number of Sundays that fell on the first of a month.

3 Answers

import datetime c = 0 for y in range(1901,2001): for m in range(1,13): d = datetime.datetime(y,m,1) if d.weekday() == 6: c += 1 print('Number of Sundays: ',c) Less

import datetime count=0 for i in range(1901,2001): for j in range(1, 13): if,j,1).weekday() == 6: count+=1 print(count) Less

Two lines of code in matlab: Answer is 171 sundays fall on the first day of the month from 1 Jan 1901 to 31 Dec 2000 dt = datenum(1901,1,1):datenum(2001,1,1)-1; sum(day(dt(weekday(dt) == 1)) == 1) Less


Write a function to return the nth fibonacci number. The first two can be assumed to be 1 and 1. The third and fourth are then calculated to be 2 and 3.

3 Answers

fib = {1:1, 2:1} def calc_fib(n): if n in fib.keys(): return fib[n] else: fib[n]=calc_fib(n-1)+calc_fib(n-2) return fib[n] print(calc_fib(9)) Less

remember how to approximate as N is large

The matlab example sets N = 12 (the 12th fab. number) which happens to be 144. N = 12; f = ones(N,1); for i = 3:N; f(i) = f(i-1) + f(i-2); end; f(end) Less


How would you write a program to move inside a square spiral? Start at the upper left corner of the square and walk its edges clockwise. Just before re-approaching the upper left corner, spiral into the square instead, ultimately arriving at the center of the square.

2 Answers

def spiral(mat): mat = np.array(mat) arr = [] if mat.shape == (1, 1): arr.append(mat[0][0]) return arr else: arr.extend(mat[0, :]) arr.extend(spiral(np.rot90(mat[1:, :]))) return arr Less

def print_spiral(matrix): print_spiral_help(matrix, 0, 0, 0, len(matrix[0]) - 1, len(matrix) - 1) def print_spiral_help(matrix, dir, top, left, right, bot): if left > right or top > bot: return # top if dir == 0: for i in range(left, right + 1): print matrix[top][i], print_spiral_help(matrix, 1, top + 1, left, right, bot) # Right elif dir == 1: for i in range(top, bot + 1): print matrix[i][right], print_spiral_help(matrix, 3, top, left, right - 1, bot) # Left elif dir == 2: for i in range(bot, top - 1, -1): print matrix[i][left], print_spiral_help(matrix, 0, top, left + 1, right, bot) # Bottom elif dir == 3: for i in range(right, left - 1, -1): print matrix[bot][i], print_spiral_help(matrix, 2, top, left, right, bot - 1) Less

Driver Group

Given a set of 50 unique DNA segments under 1000 characters that is guaranteed to overlap into one single segment, write a program that will align them.

1 Answers

I started off by building off one one end and then switching to the other. I searched for matching segments of a certain length and then tested for the overlap as I went along Less


First Round: Write a pattern 1: Should accept only odd numbers numbers only except 2: Pattern should be fully Dynamic for n =1 @@@@@ * ** *** **** ***** ****** ***** **** *** ** * @@@@@ Second Round:n=6 * ** *** **** ****** ****** ***** **** *** ** *

7 Answers

num = int(input()) for i in range(num): for j in range(num): print(" ",end=" ") for j in range(num-i): print(" ",end="") for j in range(i+1): print("*",end=" ") print() for i in range(num,0,-1): for j in range(num-i+1): print(" ",end="") for j in range(i): print("*",end=" ") print() Less

with less loops n=int(input()) print(n*"@") for i in range(1,n+2): for j in range(i): print("*",end="") print("") for i in range(n,0,-1): for j in range(i): print("*",end="") print("") print(n*"@") Less

n=int(input()) right=n-1 spaces=4*n-right-2 for i in range(1,n+1): print(spaces*' ',end='') print(i*"* ",end='') print(right*" ") spaces-=1 right-=1 spaces,right=0,0 for i in range(n,0,-1): print(spaces*' ',end='') print(i*"* ",end='') print(right*" ") spaces+=1 right+=1 Less

Show More Responses
Bank of America

Find set of chars not repeated in a list.

6 Answers

I bet you come from C++? return [x for x in li if li.count(x) == 1]

There's actually an even simpler solution: return set(li)

A=['a', 'b,' a'] Set(a) ['a', 'b']

Show More Responses

# n=3 * * * @ * @ * @ * * * #n=5 * * * @ * * * @ * * * @ * * * @ * * * @ * * * somewhat similar to these !

5 Answers

I was only able to do this : * * * @ * * * @ * * @ * @ Less

Please elaborate your question.. How question pattern looks like. It's seems in single line and you printed in multiple lines... thank-you Less

n = int(input("num")) print("* " ) print("* ", end="") print("* ", end="") print("@ ", end="") print("\n") for i in range(n-2, 0, -1): m = n-1-i for j in range(i): print("* " , end="") print("@ ", end="") for k in range(m): print("* ",end="") print("\n") print(" ", end="") print(" ", end="") print("@ ", end="") print("* ", end="") print("* ") for m in range(5): if m<4: print(" ", end="") else: print("* ") Less

Show More Responses

question on list ,sets and dictionary

4 Answers

What were the questions about in the online test and face to face round

Face to face they ask related to DS al

do you remember questions asked in online hackerrank test

Show More Responses

Given a very long string composed of numbers as characters, find the four character substring that has the largest multiple. For example, given the string "809723", the two char substring with the largest multiple is "97", having a multiple 9*7 = 63.

4 Answers

max([functools.reduce(operator.mul, data[i-4:i]) for i in data if i > 3])

max([functools.reduce(operator.mul, data[i-4:i]) for (i, e) in enumerate(data) if e > 3]) Less

def largest_2str_multipler(a): l = len(a) m = int(a[0])*int(a[1]) for x in range(1,l-1): if m < int(a[x])*int(a[x+1]): m = int(a[x])*int(a[x+1]) return m Less

Show More Responses
Fluid AI

Write a Program to print sum of even numbers which is divisible by 8:-

4 Answers

what was the question in your Hackathon round?

Share the questions of hackathon round plz

It will. Be great help if someone can update here questions of Hackathon Or round 3 . Thanks! Less

Show More Responses
Viewing 1 - 10 of 3,109 interview questions

See Interview Questions for Similar Jobs

ruby on rails developersoftware developerjava developerruby developerjavascript developerperl developerc developerpython programmerscala developerweb developerwordpress developer

Glassdoor has 3,109 interview questions and reports from Python developer interviews. Prepare for your interview. Get hired. Love your job.