0% found this document useful (0 votes)
6 views18 pages

Python Interview Questions

The document provides a comprehensive list of Python and Java interview questions covering fundamental concepts such as data types, functions, object-oriented programming, and exception handling. It includes examples and explanations for various topics like variables, loops, and modules, making it a valuable resource for interview preparation. Additionally, it highlights the uses of Python in fields like AI, web development, and automation.

Uploaded by

Suthar Dhruvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views18 pages

Python Interview Questions

The document provides a comprehensive list of Python and Java interview questions covering fundamental concepts such as data types, functions, object-oriented programming, and exception handling. It includes examples and explanations for various topics like variables, loops, and modules, making it a valuable resource for interview preparation. Additionally, it highlights the uses of Python in fields like AI, web development, and automation.

Uploaded by

Suthar Dhruvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON INTERVIEW QUESTIONS

1. What is Python?

Python is a high-level, interpreted, and object-oriented programming language used for:

 Web development

 Data science

 AI/ML

 Automation

 Scripting

✔ Easy to read because it uses simple English-like syntax.

2. What is a variable in Python?

A variable is a name used to store data.

Example:

name = "Dhruvi"

age = 20

Here, name and age store values.

3. What are Python data types?

Common data types:

 int → numbers

 float → decimal

 str → text

 bool → True/False

 list → ordered collection

 tuple → ordered + unchangeable

 dict → key-value data

Example:

student = {"name": "Riya", "age": 21}


4. What is a function?

A block of code that runs when called.

Example:

def add(a, b):

return a + b

5. What is OOP in Python?

OOP = Object-Oriented Programming

Concepts:

 Class

 Object

 Inheritance

 Polymorphism

 Encapsulation

Example:

class Student:

def __init__(self, name):

[Link] = name

s = Student("Ravi")

✅ JAVA INTERVIEW QUESTIONS (Easy + Detailed)

1. What is Java?

Java is an object-oriented, platform-independent programming language that runs on Java


Virtual Machine (JVM).

2. What is JVM, JRE, JDK?


 JVM → Runs Java programs

 JRE → Environment to run Java

 JDK → Tools to develop Java

3. What is a class and object in Java?

 Class → Blueprint

 Object → Real entity created from class

Example:

class Student {

int age;

Student s = new Student();

4. What is inheritance?

One class acquiring properties of another.

Example:

class Animal {}

class Dog extends Animal {}

5. What is method overloading and overriding?

 Overloading → Same method name, different parameters

 Overriding → Child class changes parent method

1. What is Python?

Python is a high-level, interpreted, object-oriented programming language used for web


dev, AI, ML, automation, data science, etc.

2. What are Python Data Types?


 int

 float

 str

 list

 tuple

 dict

 set

 bool

Example:

a = 10 # int

b = 10.5 # float

c = "Hello" # str

3. What is a Variable?

A container to store data.

x=5

4. What is a List?

A mutable ordered collection.

lst = [1, 2, 3]

5. What is a Tuple?

An immutable ordered collection.

tp = (1, 2, 3)

6. What is a Dictionary?

Key–value pairs.

d = {"name": "Dhruvi", "age": 20}


7. What is a Set?

Unordered unique values.

s = {1, 2, 3}

8. What is a Function?

Reusable block of code.

def add(a,b):

return a+b

9. What is lambda function?

Small anonymous function.

f = lambda x : x * 2

**10. What is *args and kwargs?

*args **kwargs

Stores multiple values Stores multiple keyword values

def test(*a):

print(a)

def test2(**k):

print(k)

11. What is Type Casting?

Convert one type to another.

int("5")

float("2.3")

str(10)
12. What is Conditional Statement?

if, elif, else

if x > 0:

print("Positive")

13. What are Loops?

For Loop:

for i in range(5):

print(i)

While Loop:

while x < 5:

x += 1

14. What is break and continue?

 break → exit loop

 continue → skip one iteration

15. What is a Module?

A Python file containing functions/classes.

import math

16. What is a Package?

A folder containing multiple modules.

17. What is pip?

Python package installer.


18. What is OOP?

Object-Oriented Programming.

Concepts:

 Class

 Object

 Inheritance

 Polymorphism

 Encapsulation

 Abstraction

19. What is a Class?

Blueprint for creating objects.

class Car:

pass

20. What is an Object?

Instance of a class.

c = Car()

21. What is init()?

Constructor method runs when object is created.

class Car:

def __init__(self, name):

[Link] = name

22. What is Inheritance?

Child class inheriting parent class properties.

class A:
pass

class B(A):

pass

23. Types of Inheritance

 Single

 Multiple

 Multilevel

 Hierarchical

 Hybrid

24. What is Polymorphism?

Same function working differently.

25. What is Encapsulation?

Hiding data using private variables (__name).

26. What is Abstraction?

Hiding implementation, showing only functionality.

27. What is an Exception?

An error that occurs during runtime.

28. How to handle exceptions?

Using try-except.

try:

print(10/0)

except:
print("Error")

29. What is finally?

Always runs.

30. What is File Handling?

Open, read, write files.

f = open("[Link]","r")

data = [Link]()

31. What is read(), readline(), readlines()?

Function Meaning

read() Read entire file

readline() Read one line

readlines() Read all lines

32. What is List Comprehension?

Short way to create lists.

[x*2 for x in range(5)]

33. What is a Decorator?

Function that modifies another function.

def deco(fn):

def inner():

print("Before")

fn()

return inner
34. What is a Generator?

Creates values using yield.

def gen():

yield 1

yield 2

35. What is Iterator?

Object with __next__() and __iter__().

36. Difference between List & Tuple

List Tuple

Mutable Immutable

Faster for updates Faster for reading

37. Difference between append() and extend()

append() extend()

Adds single element Adds multiple values

[Link](5)

[Link]([1,2])

38. Difference between remove() & pop()

remove() → value
pop() → index

39. Difference between sort() and sorted()

 sort() → changes original list

 sorted() → returns new list


40. What is Python Interpreter?

Software that executes Python code line-by-line.

41. What is pass?

Empty statement.

42. What is continue?

Skip an iteration.

43. What is break?

Stop loop.

44. What is recursion?

Function calling itself.

def fact(n):

if n==1:

return 1

return n * fact(n-1)

45. What is map(), filter(), reduce()?

map()

list(map(lambda x:x*2, [1,2,3]))

filter()

list(filter(lambda x:x%2==0, [1,2,3,4]))

reduce()

from functools import reduce

reduce(lambda a,b:a+b, [1,2,3])


46. What is a Docstring?

Comment inside triple quotes.

47. What is slicing?

Cutting string or list.

s = "hello"

s[1:4] # ell

48. What is strip()?

Removes spaces.

49. What is split()?

Splits a string.

50. What is join()?

Joins list into string.

51. What is enumerate()?

Gives index + value.

52. What is zip()?

Combines two lists.

zip(a,b)

53. What is shallow copy?

Copies only references.

54. What is deep copy?

Copies actual data.


55. What is GIL?

Global Interpreter Lock → allows only 1 thread at a time.

56. What is a Virtual Environment?

Isolated workspace for Python packages.

57. What is slicing in lists?

Extract part of list.

58. What is a boolean?

True or False.

59. What is None?

Represents empty value.

60. What is isinstance()?

Check data type.

61. What is type()?

Returns type of variable.

62. What is id()?

Memory address.

63. What is str()?

String representation of object.


64. What is repr()?

Developer-friendly representation.

65. What is try-except-else?

else runs when no exception.

66. What is max() and min()?

Return largest/smallest values.

67. What is round()?

Rounds a number.

68. What are modules in Python Standard Library?

 math

 random

 os

 datetime

 sys

69. What is list().clear()?

Deletes all elements.

70. What is [Link]()?

Safely get value.

71. What is dir()?

Shows attributes/methods.
72. What is help()?

Shows documentation.

73. What is with statement?

Used in file handling.

with open("[Link]") as f:

print([Link]())

74. What is recursion limit?

Max depth of recursion.

75. What is a binary file?

File stored in bits.

76. What is JSON module?

Used for parsing JSON.

77. What is math module?

Provides math functions.

78. What is random module?

Generates random numbers.

79. What is OS module?

For system-level operations.

80. What is sys module?

Access to Python system.


81. What is flattening list?

Convert nested list to single list.

82. What is list indexing?

Accessing elements.

83. What is negative indexing?

Indexing from end.

84. What is dictionary comprehension?

Short way to create dicts.

85. What is set comprehension?

Create sets easily.

86. What is immutability?

Value cannot change → tuple, str.

87. What is mutable?

Value can change → list, dict.

88. What is for-else?

else runs when loop ends normally.

89. What is global keyword?

Modifies global variable.


90. What is nonlocal?

Used in nested functions.

91. What is time complexity?

Measure of algorithm speed.

92. What is space complexity?

Memory usage of algorithm.

93. What is argparse?

Used for command line arguments.

94. What is CSV module?

Handle CSV files.

95. What is regex?

Pattern matching using re module.

96. What is isinstance()?

Check object type.

97. What is monkey patching?

Modify code at runtime.

98. What is shallow copy?

Copy reference.

99. What is deep copy?


Copy full object.

100. What is Python used for?

 AI/ML

 Web Development

 Automation

 Data Science

 Cyber Security

 IoT

 Software

You might also like