Top 100 Python Job Interview Questions and Answers in Hindi
Job Interview Questions and Answers: 100 Python Coding Interview Questions in Hindi
Freshers se lekar experienced candidates tak ke liye 100 original python interview questions in hindi with simple examples and code. Agar aap python coding interview ki taiyari kar rahe hain, to yah guide aapke liye hai. Aap PythonHindii.in par aur bhi Python tutorials Hindi mein aur Python basics guide free me padh sakte hain.
Python Coding Interview Questions and Answers in Hindi for Freshers and Job Preparation
Q1. kisi sankhya ka even/odd kaise jaanchen?
Uttar: kisi sankhya n ke liye agar n%2==0 hai, to wah even hai; warna odd hai. Yahi sabse simple aur standard tarika hai.
def is_even(n):
return n % 2 == 0
print(is_even(10)) # True
print(is_even(7)) # False
Q2. string ko reverse kaise karen?
Uttar: string ko ulta karne ke liye slicing ka use kiya jaata hai. [::-1] pura string reverse kar deta hai.
def reverse_string(s):
return s[::-1]
print(reverse_string("python")) # nohtyp
Q3. list me sabse bada number kaise find karen?
Uttar: max() function list ka sabse bada element return karta hai.
def largest_number(numbers):
return max(numbers)
print(largest_number([10, 5, 99, 23])) # 99
Q4. factorial kaise nikalen?
Uttar: factorial kisi number tak ke sabhi positive integers ka product hota hai. Ise loop ya recursion se nikala ja sakta hai.
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
print(factorial(5)) # 120
Q5. palindrome string kaise check karen?
Uttar: palindrome wah string hoti hai jo aage aur peeche se same padhi jaati hai.
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome("madam")) # True
print(is_palindrome("python")) # False
Q6. string me vowels kaise count karen?
Uttar: har character ko check karke vowels ki count nikali jaati hai.
def count_vowels(s):
return sum(1 for ch in s.lower() if ch in "aeiou")
print(count_vowels("Hello World")) # 3
Q7. list se duplicates kaise hataayen?
Uttar: set() duplicate values ko remove kar deta hai.
def remove_duplicates(lst):
return list(set(lst))
print(remove_duplicates([1, 2, 2, 3, 4, 4])) # [1, 2, 3, 4]
Q8. do lists ke common elements kaise nikalen?
Uttar: dono lists ko set me convert karke intersection liya jaata hai.
def common_elements(list1, list2):
return list(set(list1) & set(list2))
print(common_elements([1, 2, 3], [2, 3, 4])) # [2, 3]
Q9. do dictionaries ko merge kaise karen?
Uttar: {**dict1, **dict2} se dictionaries merge ki ja sakti hain.
def merge_dicts(d1, d2):
return {**d1, **d2}
print(merge_dicts({'a': 1}, {'b': 2})) # {'a': 1, 'b': 2}
Q10. list ko sort kaise karen?
Uttar: sorted() function list ko ascending order me sort karta hai.
def sort_numbers(numbers):
return sorted(numbers)
print(sort_numbers([5, 2, 9, 1])) # [1, 2, 5, 9]
Q11. string me har character ki frequency kaise nikalen?
Uttar: Counter ka use karke character count kiya jaata hai.
from collections import Counter
def count_characters(s):
return dict(Counter(s))
print(count_characters("hello"))
Q12. Fibonacci series kaise generate karen?
Uttar: har agla number pichhle do numbers ka sum hota hai.
def fibonacci(n):
fib = [0, 1]
while len(fib) < n:
fib.append(fib[-1] + fib[-2])
return fib[:n]
print(fibonacci(7)) # [0, 1, 1, 2, 3, 5, 8]
Q13. do sets ka intersection kaise nikalen?
Uttar: & operator common elements deta hai.
def intersection(set1, set2):
return set1 & set2
print(intersection({1, 2, 3}, {2, 3, 4})) # {2, 3}
Q14. string list ko uppercase kaise karen?
Uttar: list comprehension aur upper() ka use kiya jaata hai.
def to_uppercase(strings):
return [s.upper() for s in strings]
print(to_uppercase(["hi", "python"])) # ['HI', 'PYTHON']
Q15. len() use kiye bina list length kaise nikalen?
Uttar: list ke har element par loop chalakar count badhayi jaati hai.
def get_length(lst):
count = 0
for _ in lst:
count += 1
return count
print(get_length([1, 2, 3, 4])) # 4
Q16. do strings rotation hain ya nahi, kaise check karen?
Uttar: agar dusri string, pehli string ko double karne par usme mil jaaye, to wo rotation hain.
def are_rotations(s1, s2):
return len(s1) == len(s2) and s2 in (s1 + s1)
print(are_rotations("abcd", "cdab")) # True
Q17. list me duplicate elements kaise find karen?
Uttar: seen aur duplicates set ka use karke duplicate items nikale jaate hain.
def find_duplicates(lst):
seen = set()
duplicates = set()
for item in lst:
if item in seen:
duplicates.add(item)
else:
seen.add(item)
return list(duplicates)
print(find_duplicates([1, 2, 2, 3, 3, 4])) # [2, 3]
Q18. prime number kaise check karen?
Uttar: 1 se bada number jiske sirf do divisors hon, wah prime hota hai.
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
print(is_prime(11)) # True
Q19. second largest number kaise nikalen?
Uttar: pehle duplicates hatakar phir sorted list se dusra sabse bada element nikala jaata hai.
def second_largest(numbers):
nums = sorted(set(numbers))
return nums[-2] if len(nums) >= 2 else None
print(second_largest([10, 20, 4, 20, 8])) # 10
Q20. nested list ko flatten kaise karen?
Uttar: agar element list hai to recursively flatten kiya jaata hai.
def flatten(nested_list):
result = []
for item in nested_list:
if isinstance(item, list):
result.extend(flatten(item))
else:
result.append(item)
return result
print(flatten([1, [2, [3, 4]], 5])) # [1, 2, 3, 4, 5]
Data Structures aur Algorithm-based Python Interview Questions
Q21. binary search kaise implement karen?
Uttar: sorted list me middle element compare karke search space halve kiya jaata hai.
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
print(binary_search([1, 3, 5, 7, 9], 7)) # 3
Q22. anagram kaise check karen?
Uttar: agar dono strings ke sorted characters same hain, to wo anagram hain.
def are_anagrams(s1, s2):
return sorted(s1) == sorted(s2)
print(are_anagrams("listen", "silent")) # True
Q23. longest common prefix kaise nikalen?
Uttar: pehli string se prefix lekar baaki strings ke saath compare kiya jaata hai.
def longest_common_prefix(strs):
if not strs:
return ""
prefix = strs[0]
for s in strs[1:]:
while not s.startswith(prefix):
prefix = prefix[:-1]
return prefix
print(longest_common_prefix(["flower", "flow", "flight"])) # fl
Q24. match-case statement kaise use karen?
Uttar: yah modern Python me pattern matching ke liye use hota hai.
def get_status(code):
match code:
case 200:
return "Success"
case 404:
return "Not Found"
case _:
return "Unknown"
print(get_status(200)) # Success
Q25. stack kaise banayen?
Uttar: list me append() aur pop() se stack banaya ja sakta hai.
class Stack:
def __init__(self):
self.stack = []
def push(self, item):
self.stack.append(item)
def pop(self):
return self.stack.pop() if self.stack else None
s = Stack()
s.push(10)
s.push(20)
print(s.pop()) # 20
Q26. Python me dataclass kya hota hai?
Uttar: dataclass ka use class banane ka bojh kam karne ke liye kiya jaata hai. Yah automatically __init__, __repr__, aur __eq__ jaise methods bana deta hai.
from dataclasses import dataclass
@dataclass
class Employee:
name: str
age: int
emp = Employee("Amit", 25)
print(emp)
Q27. list ko right side me k steps rotate kaise karen?
Uttar: slicing ka use karke list ko rotate kiya ja sakta hai.
def rotate_right(lst, k):
k = k % len(lst)
return lst[-k:] + lst[:-k]
print(rotate_right([1, 2, 3, 4, 5], 2)) # [4, 5, 1, 2, 3]
Q28. alphanumeric palindrome kaise check karen?
Uttar: pehle non-alphanumeric characters hataye jaate hain, phir reverse se compare kiya jaata hai.
import re
def is_valid_palindrome(s):
s = re.sub(r'[^a-zA-Z0-9]', '', s).lower()
return s == s[::-1]
print(is_valid_palindrome("A man, a plan, a canal: Panama")) # True
Q29. recursion se power kaise nikalen?
Uttar: base ko exponent baar multiply karke power nikali jaati hai.
def power(base, exp):
if exp == 0:
return 1
return base * power(base, exp - 1)
print(power(2, 3)) # 8
Q30. zero sum wale unique triplets kaise find karen?
Uttar: list ko sort karke two-pointer approach se triplets nikale jaate hain.
def three_sum(nums):
nums.sort()
result = []
for i in range(len(nums) - 2):
if i > 0 and nums[i] == nums[i - 1]:
continue
left, right = i + 1, len(nums) - 1
while left < right:
total = nums[i] + nums[left] + nums[right]
if total == 0:
result.append([nums[i], nums[left], nums[right]])
left += 1
right -= 1
elif total < 0:
left += 1
else:
right -= 1
return result
print(three_sum([-1, 0, 1, 2, -1, -4]))
Q31. do sorted arrays ka intersection kaise find karen?
Uttar: do pointers ka use karke common values nikali jaati hain.
def intersection_sorted(arr1, arr2):
i = j = 0
result = []
while i < len(arr1) and j < len(arr2):
if arr1[i] < arr2[j]:
i += 1
elif arr1[i] > arr2[j]:
j += 1
else:
result.append(arr1[i])
i += 1
j += 1
return result
print(intersection_sorted([1, 2, 3, 4], [2, 4, 6])) # [2, 4]
Q32. LCM kaise calculate karen?
Uttar: GCD ki madad se LCM nikala ja sakta hai.
from math import gcd
def lcm(a, b):
return abs(a * b) // gcd(a, b)
print(lcm(4, 6)) # 12
Q33. anagrams ko group kaise karen?
Uttar: shabdon ko sort karke same signature wale words ko ek group me rakha jaata hai.
from collections import defaultdict
def group_anagrams(words):
groups = defaultdict(list)
for word in words:
key = ''.join(sorted(word))
groups[key].append(word)
return list(groups.values())
print(group_anagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))
Q34. LRU cache kaise implement karen?
Uttar: OrderedDict ka use karke least recently used item remove kiya jaata hai.
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity):
self.cache = OrderedDict()
self.capacity = capacity
def get(self, key):
if key not in self.cache:
return -1
self.cache.move_to_end(key)
return self.cache[key]
def put(self, key, value):
self.cache[key] = value
self.cache.move_to_end(key)
if len(self.cache) > self.capacity:
self.cache.popitem(last=False)
Q35. longest increasing subsequence kaise find karen?
Uttar: dynamic programming se har position tak longest increasing sequence track ki jaati hai.
def lis(nums):
if not nums:
return 0
dp = [1] * len(nums)
for i in range(1, len(nums)):
for j in range(i):
if nums[i] > nums[j]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)
print(lis([10, 9, 2, 5, 3, 7, 101, 18])) # 4
Q36. binary tree aur inorder traversal kaise karen?
Uttar: inorder traversal me left subtree, root, aur phir right subtree visit kiya jaata hai.
class Node:
def __init__(self, key):
self.left = None
self.right = None
self.value = key
def inorder(root):
if root:
inorder(root.left)
print(root.value, end=" ")
inorder(root.right)
Q37. valid parentheses combinations kaise generate karen?
Uttar: backtracking se sabhi valid combinations banaye jaate hain.
def generate_parentheses(n):
def backtrack(s='', left=0, right=0):
if len(s) == 2 * n:
result.append(s)
return
if left < n:
backtrack(s + '(', left + 1, right)
if right < left:
backtrack(s + ')', left, right + 1)
result = []
backtrack()
return result
print(generate_parentheses(3))
Q38. do stacks se queue kaise banayen?
Uttar: ek stack me enqueue aur dusre me dequeue operations kiye jaate hain.
class Queue:
def __init__(self):
self.stack1 = []
self.stack2 = []
def enqueue(self, item):
self.stack1.append(item)
def dequeue(self):
if not self.stack2:
while self.stack1:
self.stack2.append(self.stack1.pop())
return self.stack2.pop() if self.stack2 else None
Q39. do integers ka maximum product kaise nikalen?
Uttar: sabse bade do numbers aur sabse chhote do numbers dono consider kiye jaate hain.
def max_product(lst):
if len(lst) < 2:
return None
lst.sort()
return max(lst[-1] * lst[-2], lst[0] * lst[1])
print(max_product([-10, -3, 5, 6, -2])) # 30
Q40. median ko linear time me kaise find karen?
Uttar: quickselect algorithm se median ko average linear time me nikala ja sakta hai.
import random
def quickselect(arr, k):
if len(arr) == 1:
return arr[0]
pivot = random.choice(arr)
lows = [x for x in arr if x < pivot]
highs = [x for x in arr if x > pivot]
pivots = [x for x in arr if x == pivot]
if k < len(lows):
return quickselect(lows, k)
elif k < len(lows) + len(pivots):
return pivots[0]
else:
return quickselect(highs, k - len(lows) - len(pivots))
def find_median(nums):
n = len(nums)
if n % 2 == 1:
return quickselect(nums, n // 2)
return (quickselect(nums, n // 2 - 1) + quickselect(nums, n // 2)) / 2
Q41. N-Queens problem kaise solve karen?
Uttar: backtracking ke jariye queens ko aisi jagah rakha jaata hai jahan wo ek-dusre ko attack na karen.
def solve_n_queens(n):
def backtrack(row, cols, d1, d2):
if row == n:
result.append(board[:])
return
for col in range(n):
if col in cols or (row - col) in d1 or (row + col) in d2:
continue
board[row] = col
cols.add(col)
d1.add(row - col)
d2.add(row + col)
backtrack(row + 1, cols, d1, d2)
cols.remove(col)
d1.remove(row - col)
d2.remove(row + col)
result = []
board = [-1] * n
backtrack(0, set(), set(), set())
return result
Q42. Dijkstra's algorithm kaise implement karen?
Uttar: yah weighted graph me shortest path find karne ke liye use hota hai.
import heapq
def dijkstra(graph, start):
min_heap = [(0, start)]
distances = {node: float('inf') for node in graph}
distances[start] = 0
while min_heap:
current_distance, current_node = heapq.heappop(min_heap)
if current_distance > distances[current_node]:
continue
for neighbor, weight in graph[current_node].items():
distance = current_distance + weight
if distance < distances[neighbor]:
distances[neighbor] = distance
heapq.heappush(min_heap, (distance, neighbor))
return distances
Q43. asyncio ke saath asynchronous programming kaise use karen?
Uttar: async aur await ka use karke tasks ko concurrently run kiya jaata hai.
import asyncio
async def fetch_data():
await asyncio.sleep(2)
return "Data Retrieved"
async def main():
result = await fetch_data()
print(result)
asyncio.run(main())
Q44. Python decorators kya hote hain?
Uttar: decorators functions ke behavior ko bina source code badle modify karte hain.
def logger(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper
@logger
def greet():
print("Hello World")
greet()
Q45. longest palindromic substring kaise find karen?
Uttar: har character ko center maankar palindrome expand kiya jaata hai.
def longest_palindrome(s):
def expand(left, right):
while left >= 0 and right < len(s) and s[left] == s[right]:
left -= 1
right += 1
return right - left - 1
start = end = 0
for i in range(len(s)):
len1 = expand(i, i)
len2 = expand(i, i + 1)
max_len = max(len1, len2)
if max_len > end - start:
start = i - (max_len - 1) // 2
end = i + max_len // 2
return s[start:end + 1]
Q46. target sum wali combinations kaise find karen?
Uttar: backtracking se sabhi valid combinations nikali jaati hain.
def combination_sum(candidates, target):
def backtrack(start, path, total):
if total == target:
result.append(path)
return
if total > target:
return
for i in range(start, len(candidates)):
backtrack(i, path + [candidates[i]], total + candidates[i])
result = []
backtrack(0, [], 0)
return result
Q47. maze me shortest path BFS se kaise nikalen?
Uttar: BFS level by level search karta hai, isliye shortest path mil jaata hai.
from collections import deque
def shortest_path(maze, start, end):
rows, cols = len(maze), len(maze[0])
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(start, 0)])
visited = {start}
while queue:
(x, y), steps = queue.popleft()
if (x, y) == end:
return steps
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < rows and 0 <= ny < cols and maze[nx][ny] == 0 and (nx, ny) not in visited:
visited.add((nx, ny))
queue.append(((nx, ny), steps + 1))
return -1
Q48. directed graph me cycle kaise detect karen?
Uttar: DFS ke dauraan recursion path ko track karke cycle pakdi jaati hai.
def has_cycle(graph):
def dfs(node):
if node in visiting:
return True
if node in visited:
return False
visiting.add(node)
for neighbor in graph[node]:
if dfs(neighbor):
return True
visiting.remove(node)
visited.add(node)
return False
visited, visiting = set(), set()
for vertex in graph:
if dfs(vertex):
return True
return False
Q49. longest substring without repeating characters kaise find karen?
Uttar: sliding window technique ka use kiya jaata hai.
def length_of_longest_substring(s):
char_index = {}
max_length = start = 0
for index, char in enumerate(s):
if char in char_index and char_index[char] >= start:
start = char_index[char] + 1
char_index[char] = index
max_length = max(max_length, index - start + 1)
return max_length
print(length_of_longest_substring("abcabcbb")) # 3
Q50. large dataset process karte samay memory kaise bachayen?
Uttar: generators ka use karke data ko ek-ek karke process kiya jaata hai.
def read_large_file(file_path):
with open(file_path, "r") as file:
for line in file:
yield line.strip()
Python Practice Programs: List, String, Dictionary aur Tuple Questions
Q51. list aur tuple me kya antar hai?
Uttar: list mutable hoti hai, jabki tuple immutable hoti hai. list ko baad me badla ja sakta hai, lekin tuple ko nahi.
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
my_list.append(4)
print(my_list) # [1, 2, 3, 4]
print(my_tuple) # (1, 2, 3)
Q52. dictionary me key ki presence kaise check karen?
Uttar: in keyword se check kiya jaata hai ki key dictionary me hai ya nahi.
def has_key(d, key):
return key in d
print(has_key({"a": 1, "b": 2}, "a")) # True
Q53. Python me swap kaise karen?
Uttar: Python me two variables ko bina extra variable ke swap kiya ja sakta hai.
a = 5
b = 10
a, b = b, a
print(a, b) # 10 5
Q54. string ko words me split kaise karen?
Uttar: split() method string ko shabdon ki list me badal deti hai.
def split_words(s):
return s.split()
print(split_words("hello python world")) # ['hello', 'python', 'world']
Q55. list me odd numbers kaise filter karen?
Uttar: list comprehension se odd numbers nikale ja sakte hain.
def odd_numbers(lst):
return [x for x in lst if x % 2 != 0]
print(odd_numbers([1, 2, 3, 4, 5])) # [1, 3, 5]
Q56. list me even numbers kaise filter karen?
Uttar: jin numbers ko 2 se divide karne par remainder 0 aaye, wo even hote hain.
def even_numbers(lst):
return [x for x in lst if x % 2 == 0]
print(even_numbers([1, 2, 3, 4, 5])) # [2, 4]
Q57. string me pehla non-repeating character kaise find karen?
Uttar: pehle character frequency count karke phir pehla unique character nikala jaata hai.
from collections import Counter
def first_unique_char(s):
freq = Counter(s)
for ch in s:
if freq[ch] == 1:
return ch
return None
print(first_unique_char("swiss")) # w
Q58. list ko ascending order me sort kaise karen?
Uttar: sorted() ya sort() method ka use kiya jaata hai.
def sort_ascending(lst):
return sorted(lst)
print(sort_ascending([5, 1, 4, 2])) # [1, 2, 4, 5]
Q59. dictionary ke values kaise nikalen?
Uttar: values() method dictionary ke sabhi values return karti hai.
def get_values(d):
return list(d.values())
print(get_values({"a": 1, "b": 2})) # [1, 2]
Q60. dictionary ke keys kaise nikalen?
Uttar: keys() method se sabhi keys milti hain.
def get_keys(d):
return list(d.keys())
print(get_keys({"a": 1, "b": 2})) # ['a', 'b']
Q61. list ka sum kaise nikalen?
Uttar: sum() function list ke sabhi elements jod deta hai.
def list_sum(lst):
return sum(lst)
print(list_sum([1, 2, 3, 4])) # 10
Q62. list ka average kaise nikalen?
Uttar: total sum ko number of elements se divide kiya jaata hai.
def average(lst):
return sum(lst) / len(lst)
print(average([10, 20, 30])) # 20.0
Q63. string me spaces kaise remove karen?
Uttar: replace() method se spaces hataye jaate hain.
def remove_spaces(s):
return s.replace(" ", "")
print(remove_spaces("hello python")) # hellopython
Q64. list ko reverse kaise karen?
Uttar: slicing [::-1] ya reverse() method ka use kiya jaata hai.
def reverse_list(lst):
return lst[::-1]
print(reverse_list([1, 2, 3])) # [3, 2, 1]
Q65. prime numbers ki list kaise banayen?
Uttar: har number par prime check karke nayi list banayi jaati hai.
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def primes_upto(n):
return [x for x in range(2, n + 1) if is_prime(x)]
print(primes_upto(20))
Q66. string me digits kaise count karen?
Uttar: har character ko check karke digits gine jaate hain.
def count_digits(s):
return sum(1 for ch in s if ch.isdigit())
print(count_digits("a1b2c3")) # 3
Q67. string me uppercase letters kaise count karen?
Uttar: isupper() use karke uppercase characters count kiye jaate hain.
def count_uppercase(s):
return sum(1 for ch in s if ch.isupper())
print(count_uppercase("Hello Python")) # 2
Q68. string me lowercase letters kaise count karen?
Uttar: islower() se lowercase letters count kiye jaate hain.
def count_lowercase(s):
return sum(1 for ch in s if ch.islower())
print(count_lowercase("Hello Python")) # 9
Q69. string ka length manually kaise nikalen?
Uttar: characters ko iterate karke counter badhaya jaata hai.
def manual_length(s):
count = 0
for _ in s:
count += 1
return count
print(manual_length("python")) # 6
Q70. list me maximum aur minimum kaise find karen?
Uttar: max() aur min() functions ka use kiya jaata hai.
def find_max_min(lst):
return max(lst), min(lst)
print(find_max_min([10, 5, 30, 2])) # (30, 2)
Q71. do numbers ka GCD kaise find karen?
Uttar: Euclidean algorithm ya math.gcd() ka use kiya jaata hai.
from math import gcd
def find_gcd(a, b):
return gcd(a, b)
print(find_gcd(12, 18)) # 6
Q72. list me positive numbers kaise filter karen?
Uttar: jin numbers ka value 0 se bada ho, unhe chun liya jaata hai.
def positive_numbers(lst):
return [x for x in lst if x > 0]
print(positive_numbers([-1, 2, -3, 4])) # [2, 4]
Q73. list me negative numbers kaise filter karen?
Uttar: 0 se chhote numbers ko filter kiya jaata hai.
def negative_numbers(lst):
return [x for x in lst if x < 0]
print(negative_numbers([-1, 2, -3, 4])) # [-1, -3]
Q74. string ko title case me kaise badlen?
Uttar: title() method har word ka pehla letter capital kar deta hai.
def to_title_case(s):
return s.title()
print(to_title_case("hello python world")) # Hello Python World
Q75. list me repeated items kaise count karen?
Uttar: Counter se har item ki frequency milti hai.
from collections import Counter
def count_repeated_items(lst):
return dict(Counter(lst))
print(count_repeated_items([1, 2, 2, 3, 3, 3]))
Q76. string me count kaise karen ki koi word kitni baar aaya hai?
Uttar: Counter ya loop se word frequency nikali ja sakti hai.
from collections import Counter
def word_count(sentence):
return dict(Counter(sentence.split()))
print(word_count("python is easy and python is powerful"))
Q77. list ke sabhi elements ko string me kaise convert karen?
Uttar: map(str, lst) ya list comprehension ka use kiya jaata hai.
def list_to_strings(lst):
return [str(x) for x in lst]
print(list_to_strings([1, 2, 3])) # ['1', '2', '3']
Q78. list ke sabhi elements ka product kaise nikalen?
Uttar: loop se har number ko multiply kiya jaata hai.
def list_product(lst):
result = 1
for num in lst:
result *= num
return result
print(list_product([1, 2, 3, 4])) # 24
Q79. list me repeated numbers ko remove karke unique list kaise banayen?
Uttar: set() duplicate values hata deta hai.
def unique_list(lst):
return list(set(lst))
print(unique_list([1, 1, 2, 3, 3, 4]))
Q80. list ko chunks me kaise divide karen?
Uttar: slicing se list ko chhote parts me toda jaata hai.
def chunk_list(lst, size):
return [lst[i:i+size] for i in range(0, len(lst), size)]
print(chunk_list([1, 2, 3, 4, 5, 6], 2))
Q81. list me har element ki square value kaise nikalen?
Uttar: list comprehension se squares banaye jaate hain.
def squares(lst):
return [x * x for x in lst]
print(squares([1, 2, 3, 4])) # [1, 4, 9, 16]
Q82. list me har element ki cube value kaise nikalen?
Uttar: har number ko 3 se multiply nahi, balki power 3 kiya jaata hai.
def cubes(lst):
return [x ** 3 for x in lst]
print(cubes([1, 2, 3])) # [1, 8, 27]
Q83. string me first letter capital kaise karen?
Uttar: capitalize() first character ko uppercase kar deta hai.
def first_capital(s):
return s.capitalize()
print(first_capital("python language")) # Python language
Q84. list me even index wale elements kaise nikalen?
Uttar: slicing lst[::2] se even index wale elements milte hain.
def even_index_elements(lst):
return lst[::2]
print(even_index_elements([10, 20, 30, 40, 50])) # [10, 30, 50]
Q85. list me odd index wale elements kaise nikalen?
Uttar: slicing lst[1::2] use kiya jaata hai.
def odd_index_elements(lst):
return lst[1::2]
print(odd_index_elements([10, 20, 30, 40, 50])) # [20, 40]
Q86. list me elements ko pair-wise print kaise karen?
Uttar: loop ko step 2 se chalakar pairs banaye jaate hain.
def print_pairs(lst):
return [(lst[i], lst[i+1]) for i in range(0, len(lst)-1, 2)]
print(print_pairs([1, 2, 3, 4, 5, 6]))
Q87. string ko lowercase me kaise badlen?
Uttar: lower() method ka use kiya jaata hai.
def to_lowercase(s):
return s.lower()
print(to_lowercase("Hello Python")) # hello python
Q88. list me kisi value ka index kaise find karen?
Uttar: index() method us value ki position return karti hai.
def find_index(lst, value):
return lst.index(value)
print(find_index([5, 10, 15], 10)) # 1
Q89. string ke starting aur ending character kaise check karen?
Uttar: startswith() aur endswith() methods use hoti hain.
def check_start_end(s, start_char, end_char):
return s.startswith(start_char), s.endswith(end_char)
print(check_start_end("python", "p", "n")) # (True, True)
Q90. dictionary me naya key-value pair kaise add karen?
Uttar: key assign karke naya pair jod diya jaata hai.
def add_key_value(d, key, value):
d[key] = value
return d
print(add_key_value({"a": 1}, "b", 2))
Q91. dictionary se kisi key ko kaise remove karen?
Uttar: pop() ya del ka use kiya jaata hai.
def remove_key(d, key):
d.pop(key, None)
return d
print(remove_key({"a": 1, "b": 2}, "a"))
Q92. list me elements ko alphabetically sort kaise karen?
Uttar: strings wali list ko sorted() se sort kiya jaata hai.
def sort_strings(lst):
return sorted(lst)
print(sort_strings(["banana", "apple", "mango"]))
Q93. list ko tuple me kaise convert karen?
Uttar: tuple() function list ko tuple me badal deta hai.
def list_to_tuple(lst):
return tuple(lst)
print(list_to_tuple([1, 2, 3])) # (1, 2, 3)
Q94. tuple ko list me kaise convert karen?
Uttar: list() function tuple ko list me badal deta hai.
def tuple_to_list(tup):
return list(tup)
print(tuple_to_list((1, 2, 3))) # [1, 2, 3]
Q95. string me specific character kitni baar aaya hai?
Uttar: count() method character occurrences ginti hai.
def count_character(s, ch):
return s.count(ch)
print(count_character("banana", "a")) # 3
Q96. list me pehla aur aakhiri element kaise nikalen?
Uttar: indexing se first aur last element milte hain.
def first_last(lst):
return lst[0], lst[-1]
print(first_last([10, 20, 30, 40])) # (10, 40)
Q97. string ke sabhi characters ko list me kaise convert karen?
Uttar: list() function string ko characters ki list me badal deta hai.
def string_to_list(s):
return list(s)
print(string_to_list("python")) # ['p', 'y', 't', 'h', 'o', 'n']
Q98. list me all elements unique hain ya nahi, kaise check karen?
Uttar: list ki length aur set ki length compare ki jaati hai.
def all_unique(lst):
return len(lst) == len(set(lst))
print(all_unique([1, 2, 3])) # True
print(all_unique([1, 2, 2])) # False
Q99. string me vowels aur consonants kaise count karen?
Uttar: har character ko check karke vowels aur consonants count kiye jaate hain.
def count_vowels_consonants(s):
vowels = "aeiou"
v = c = 0
for ch in s.lower():
if ch.isalpha():
if ch in vowels:
v += 1
else:
c += 1
return v, c
print(count_vowels_consonants("Hello Python"))
Q100. simple calculator Python me kaise banayen?
Uttar: basic arithmetic operations functions se ki jaati hain.
def calculator(a, b, op):
if op == "+":
return a + b
elif op == "-":
return a - b
elif op == "*":
return a * b
elif op == "/":
return a / b if b != 0 else "Division by zero not allowed"
else:
return "Invalid operator"
print(calculator(10, 5, "+")) # 15
FAQ — Python Interview Questions in Hindi
Q1. Python interview questions ki taiyari kaise karen?
Python interview ki taiyari ke liye basics, data structures, functions, OOP, file handling, aur coding practice par focus karen. Roz 5-10 questions solve karna sabse effective tarika hai.
Q2. Python interview me sabse zyada kaun se topics puchhe jaate hain?
Interviews me list, tuple, dictionary, set, string, loops, recursion, aur OOP concepts baar-baar puchhe jaate hain. Saath hi problem-solving aur clean coding bhi check kiya jaata hai.
Q3. kya freshers ke liye Python jobs available hain?
Haan, freshers ke liye Python roles available hain, khaaskar automation, web development, data support, aur scripting areas me. India me Python developer demand bani hui hai.
Q4. Python seekhne ke baad kaun-kaun si jobs mil sakti hain?
Python seekhne ke baad aap Python developer, automation tester, backend developer, data analyst, scripting engineer, ya ML assistant jaisi roles ke liye apply kar sakte hain.
Q5. kya Python interview questions ka practice roz karna zaruri hai?
Haan, roz practice karne se logic strong hota hai aur interview pressure kam hota hai. Khaaskar coding questions me speed aur accuracy dono improve hoti hain.
Conclusion
Python interview preparation ke liye sirf theory padhna kaafi nahi hai; aapko questions ko solve karna, concepts ko explain karna, aur code ko khud likhna bhi aana chahiye. Is article me diye gaye 100 questions freshers se lekar experienced level tak cover karte hain, isliye yah interview revision ke liye useful rahega. Agar aap inhe regular practice ke saath revise karte hain, to Python basics par aapki pakad mazboot ho jaayegi aur interview confidence bhi badhega.
Aur zyada practice ke liye PythonHindii.in par visit karte rahiye aur naye python interview questions in hindi ke updates paate rahiye.
Related Articles
рдХोрдИ рдЯिрдк्рдкрдгी рдирд╣ीं:
рдПрдХ рдЯिрдк्рдкрдгी рднेрдЬें