python_interview_q_swaroop_ig
python_interview_q_swaroop_ig
python_interview_q_swaroop_ig
1. What is Python? Python is a high-level, interpreted programming language known for its
simplicity and readability. It supports multiple programming paradigms, including procedural,
object-oriented, and functional programming.
2. Why Python? Python is favored for its simplicity, readability, and extensive standard library.
It's versatile, used in web development, data analysis, artificial intelligence, scientific computing,
and more.
5. What do you mean by Python literals? Literals are fixed values in Python that are directly
assigned to variables. Examples include string literals, numeric literals, boolean literals, and
special literals like None.
6. What is Python Identifiers? Identifiers are names used to identify variables, functions,
classes, modules, etc. in Python. They must start with a letter (A-Z or a-z) or an underscore (_),
followed by letters, underscores, or digits (0-9).
7. What is a Keyword? Keywords are reserved words in Python with special meanings.
Examples include if, else, while, return, True, and False.
10. What is Explicit Type Conversion? Explicit type conversion, or casting, is when the
programmer manually converts one data type to another using functions like int(), float(),
str(), etc.
11. What is a Variable? A variable is a named location in memory used to store data. It can
hold different data types and can be changed during program execution.
● Input: input()
● Output: print()
● Integers (int)
● Floating-point numbers (float)
● Strings (str)
● Booleans (bool)
14. What is the use of type() function in Python? The type() function returns the type of an
object or variable.
15. What are Python Numbers? Python numbers include integers, floating-point numbers, and
complex numbers.
16. What is Boolean datatype? The boolean datatype (bool) represents two values: True
and False.
17. What are Python Operators? Operators are special symbols in Python used for arithmetic,
comparison, logical operations, etc.
Arithmetic Operators
18. Python Arithmetic Operators:
● + Addition
● - Subtraction
● * Multiplication
● / Division
● % Modulus
● ** Exponentiation
● // Floor division
Comparison Operators
● == Equal to
● != Not equal to
● > Greater than
● < Less than
● >= Greater than or equal to
● <= Less than or equal to
Logical Operators
Identity Operators
● is Object identity
● is not Negated object identity
Membership Operators
Bitwise Operators
● & AND
● | OR
● ^ XOR
● ~ NOT
● << Left shift
● >> Right shift
Assignment Operators
● = Assignment
● += Addition assignment
● -= Subtraction assignment
● *= Multiplication assignment
● /= Division assignment
● %= Modulus assignment
● **= Exponentiation assignment
● //= Floor division assignment
25. What is operator precedence in Python? Operator precedence determines the order in
which operations are evaluated. For example, multiplication and division have higher
precedence than addition and subtraction.
26. What is Associativity of Python Operators? Associativity determines the order in which
operators of the same precedence are processed. Most operators are left-associative, meaning
they are evaluated from left to right.
Control Flow
27. What are Conditionals statements in Python? Conditional statements include if, elif,
and else, used to execute code blocks based on conditions.
28. What are Repetition Statements (loops) in Python? Repetition statements include for
and while loops, used to execute code repeatedly.
for i in range(10):
if i == 5:
break
print(i)
for i in range(10):
if i == 5:
continue
print(i)
Miscellaneous
32. What is PEP 8? PEP 8 is the Python Enhancement Proposal that provides guidelines and
best practices on how to write Python code.
33. What is PIP, what is its use? PIP is the package installer for Python, used to install and
manage software packages written in Python.
Mutable vs Immutable
● Mutable: Objects that can be changed after creation (e.g., lists, dictionaries).
● Immutable: Objects that cannot be changed after creation (e.g., strings, tuples).
39. What is list comprehension? List comprehension provides a concise way to create lists.
Example:
40. What is list slicing? List slicing allows you to access a portion of a list. Example:
a = [1, 2, 3, 4, 5]
print(a[1:4]) # Output: [2, 3, 4]
Dictionaries
41. What are Dictionaries? Give examples: Dictionaries are collections of key-value pairs.
Example:
d = {'a': 1, 'b': 2}
● Array: Requires importing the array module, supports only homogeneous data types.
● List: Built-in, supports heterogeneous data types.
43. What are Built-in libraries in Python? Examples include os, sys, math, datetime,
json.
44. Explain Negative indexing in Python: Negative indexing starts from the end of the list,
with -1 being the last item. Example:
a = [1, 2, 3, 4, 5]
print(a[-1]) # Output: 5
Functions
45. What is a function? What are Built-in functions? A function is a block of code that
performs a specific task. Built-in functions are provided by Python, such as print(), len(),
type().
46. Use of functions in Python? Functions provide code reusability, modularity, and
abstraction.
def my_function():
pass
Arguments
● Positional arguments
● Keyword arguments
● Default arguments
● Variable-length arguments
Positional Arguments
50. Positional Arguments: Arguments passed to a function in the correct positional order.
51. Default Arguments in Python: Arguments that assume a default value if not provided.
Example:
Keyword Arguments
52. Keyword arguments: Arguments passed to a function by explicitly stating the parameter
name.
Variable-length Arguments
56. What is lambda and its function in programming: A lambda is an anonymous function
defined using the lambda keyword. Example:
add = lambda x, y: x + y
57. What is recursion? Recursion is a process where a function calls itself directly or indirectly.
58. What is namespace in Python? A namespace is a container that holds a set of identifiers
(variable names) and ensures that names are unique and won't conflict.
60. Why we use OOP? OOP promotes code reusability, modularity, and scalability.
62. What is the difference between a class and a structure? In Python, there is no
structure. Classes can have methods, while a structure (in other languages) typically cannot.
● Encapsulation
● Inheritance
● Polymorphism
● Abstraction
Procedural vs OOP
65. What is inheritance? Inheritance is a mechanism where one class (child) inherits attributes
and methods from another class (parent).
● Single inheritance
● Multiple inheritance
● Multilevel inheritance
● Hierarchical inheritance
● Hybrid inheritance
67. What is polymorphism? Polymorphism allows methods to do different things based on the
object it is acting upon.
68. What is Encapsulation? Encapsulation is the bundling of data and methods into a single
unit (class) and restricting access to certain components.
69. What is Data Abstraction? Data abstraction is the process of hiding the implementation
details and showing only the functionality.
71. What are ‘access specifiers’? Access specifiers define the accessibility of the members of
a class.
72. What is the difference between public, private, and protected access modifiers?