0% found this document useful (0 votes)
2 views10 pages

python_interview_q_swaroop_ig

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10



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.

3. What is the difference between C and Python?

● Syntax: Python has a simpler, more readable syntax than C.


● Compilation: C is a compiled language, whereas Python is interpreted.
● Performance: C is generally faster due to its compiled nature, but Python is more
productive due to its ease of use.
● Memory Management: C requires manual memory management; Python uses
automatic garbage collection.

4. What are the applications of Python?

● Web development (Django, Flask)


● Data Science and Machine Learning (Pandas, NumPy, Scikit-learn)
● Scripting and Automation
● Scientific Computing (SciPy)
● Game Development (Pygame)
● Software Development and Prototyping

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.

Data Types and Variables


8. What is type conversion? Type conversion refers to converting one data type into another.
It can be implicit or explicit.

9. What is Implicit Type Conversion? Implicit type conversion, or coercion, occurs


automatically when Python converts data types without user intervention, such as adding an
integer to a float.

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.

12. Input/Output Statements in Python?

● Input: input()
● Output: print()

13. What are the Basic Data Types in Python?

● 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.

Numbers and Operators

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

19. Python Comparison Operators:

● == Equal to
● != Not equal to
● > Greater than
● < Less than
● >= Greater than or equal to
● <= Less than or equal to

Logical Operators

20. Python Logical Operators:

● and Logical AND


● or Logical OR
● not Logical NOT

Identity Operators

21. Python Identity Operators:

● is Object identity
● is not Negated object identity

Membership Operators

22. Python Membership Operators:


● in Membership
● not in Negated membership

Bitwise Operators

23. Python Bitwise Operators:

● & AND
● | OR
● ^ XOR
● ~ NOT
● << Left shift
● >> Right shift

Assignment Operators

24. Python 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.

Break and Continue

29. What is the use of Break and Continue in Python?

● Break: Exits the current loop prematurely.


● Continue: Skips the rest of the code inside the current loop iteration and moves to the
next iteration.

30. Python break statement:

for i in range(10):
if i == 5:
break
print(i)

31. Python continue statement:

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.

34. Is Python a scripting language or programming language? Python is both a scripting


language and a general-purpose programming language.

35. Is Python a case-sensitive language? Yes, Python is case-sensitive.

36. Interpreter vs Compiler:

● Interpreter: Executes code line by line, such as Python.


● Compiler: Translates the entire code into machine language before execution, such as
C.

Mutable vs Immutable

37. Difference between mutable and 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).

38. Difference between lists and tuples:

● Lists: Mutable, can change their contents.


● Tuples: Immutable, cannot change their contents.

39. What is list comprehension? List comprehension provides a concise way to create lists.
Example:

squares = [x**2 for x in range(10)]

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}

42. Difference between array and list:

● 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.

47. How to define a function in Python?

def my_function():
pass

Arguments

48. Difference between Parameters & Arguments?

● Parameters: Variables listed in the function definition.


● Arguments: Values passed to the function during the function call.

49. Types of Arguments in Python:

● 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:

def my_function(a, b=2):


pass

Keyword Arguments
52. Keyword arguments: Arguments passed to a function by explicitly stating the parameter
name.

Variable-length Arguments

53. Variable-length Arguments in Python: Allows a function to accept any number of


arguments. Example:

def my_function(*args, **kwargs):


pass

Scope and Lifetime

54. Difference between Scope and Lifetime:

● Scope: The region of code where a variable is accessible.


● Lifetime: The duration for which a variable exists in memory.

55. Difference between Local and Global Variables:

● Local: Defined inside a function, accessible only within that function.


● Global: Defined outside all functions, accessible throughout the program.

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.

Object-Oriented Programming (OOP)

59. What is Object-Oriented Programming? OOP is a programming paradigm based on the


concept of objects containing data and methods.

60. Why we use OOP? OOP promotes code reusability, modularity, and scalability.

61. What is an Object? What is a Class?


● Object: An instance of a class.
● Class: A blueprint for creating objects.

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.

63. What are the main features of OOP?

● Encapsulation
● Inheritance
● Polymorphism
● Abstraction

Procedural vs OOP

64. Difference between Procedural programming and OOP:

● Procedural: Focuses on functions and procedures.


● OOP: Focuses on objects and classes.

65. What is inheritance? Inheritance is a mechanism where one class (child) inherits attributes
and methods from another class (parent).

66. What are the different types of inheritance?

● 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.

70. Differentiate between data abstraction and encapsulation:

● Abstraction: Focuses on hiding the complexity.


● Encapsulation: Focuses on bundling the data and methods.
Access Specifiers

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?

● Public: Accessible from anywhere.


● Protected: Accessible within the class and its subclasses (prefix _).
● Private: Accessible only within the class (prefix __).

You might also like