User FAQs


Python supports object-orientated programming as you can define classes along with the composition and inheritance.
Functions in Python are like first-class objects. It suggests you can assign them to variables, return from other methods and pass them as arguments.
Developing using Python is quick but running it is often slower than compiled languages.
Python has several usages like web-based applications, test automation, data modeling, big data analytics, and much more.


1) Is Python a compiled language or an interpreted language?
Please remember one thing, whether a language is compiled or interpreted or both is not defined in the language standard. In other words, it is not a properly of a programming language.
Different Python distributions (or implementations) choose to do different things (compile or interpret or both).
However the most common implementations like CPython do both compile and interpret, but in different stages of its execution process.


Compilation:
When you write Python code and run it, the source code (.py files) is first compiled into an intermediate form called bytecode (.pyc files).
This bytecode is a lower-level representation of your code, but it is still not directly machine code. It's something that the Python Virtual Machine (PVM) can understand and execute.


Interpretation:
After Python code is compiled into bytecode, it is executed by the Python Virtual Machine (PVM), which is an interpreter.
The PVM reads the bytecode and executes it line-by-line at runtime, which is why Python is considered an interpreted language in practice.


Some implementations, like PyPy, use Just-In-Time (JIT) compilation, where Python code is compiled into machine code at runtime for faster execution, blurring the lines between interpretation and compilation.


2) Is Python a dynamically typed programming language ?
In a dynamically typed language, the data type of a variable is determined at runtime, not at compile time.
Python and JavaScript are both dynamically typed.
No need to declare data types manually; Python automatically detects it based on the assigned value.

x = 10       # x is an integer 
x = "Hello" # Now x is a string

3) Is Indentation Required in Python?
Yes, indentation is required in Python. A Python interpreter can be informed that a group of statements belongs to a specific block of code by using Python indentation.
Indentations make the code easy to read for developers in all programming languages but in Python, it is very important to indent the code in a specific order.


4) Can we pass a function as an argument ?
Yes, Several arguments can be passed to a function, including objects, variables (of the same or distinct data types) and functions.
Functions can be passed as parameters to other functions because they are objects.
Higher-order functions are functions that can take other functions as arguments.

def add(x, y): 
    return x + y

def apply_func(func, a, b):
    return func(a, b)

print(apply_func(add, 3, 5))



5) What is the Standard Library ?
The library contains a collection of modules (written in Python or C)
The windows installation includes the entire standard library as well as some additional components
The unix installation is provided as a collection of packages


6) What is a Module ?
A module is a single Python file (.py)
Example - math.py is a module


7) What is a Library ?
A library is a collection of modules packaged together
Example - NumPy is a library
Example - Pandas is a library


8) Is Python an Object Orientated programming language ?
Yes it is an interpreted and object orientated. It also supports procedural and functional programming
Python is a high level general purpose programming language.


9) What is the Python Software Foundation ?
This is the name of the organization that holds the copyright on Python 2.1 and later versions.


10) Are there any coding standards ?

link - peps.python.org/pep-0008/ 

11) Is Python open source ?



12) How can you concatenate two lists in Python?
Using the +operator or the extend() method.

a = [1, 2, 3] 
b = [4, 5, 6]

res = a + b
print(res) ' [1, 2, 3, 4, 5, 6]
a.extend(b)
print(a) ' [1, 2, 3, 4, 5, 6]

13) What is the difference between for loop and while loop in Python
For loop: Used when we know how many times to repeat, often with lists, tuples, sets, or dictionaries.
While loop: Used when we only have an end condition and don't know exactly how many times it will repeat.

for i in range(5): 
    print(i)

c = 0
while c < 5:
    print(c)
    c += 1

14) What is the difference between / and // in Python?
/ represents precise division (result is a floating point number)
// represents floor division (result is an integer)

print(5//2)     ' 2  
print(5/2) ' 2.5

15) Are there many third party libraries ?
Yes, these can all be seen on:

link - pypi.org 

16) How can I define a 1-dimensional array ?
["this",1,"is","an","array"]


17) How can I define a 2-dimensional array ?


18) What is a tuple ?


19) What is the difference between lists, tuples and sets?
Lists, tuples, and sets are all used to store multiple items in a single variable, but they have different properties:
A list is ordered and changeable. It allows duplicate values.
A tuple is ordered but unchangeable (immutable). It also allows duplicates.
A set is unordered, unindexed, and contains only unique items. It is changeable, but you cannot modify individual elements by index.


20) When to use a tuple vs list vs dictionary in Python?
Use a tuple to store a sequence of items that will not change.
Use a list to store a sequence of items that may change.
Use a dictionary when you want to associate pairs of two items.


21) How can I convert between a tuple and a list ?


22) What is self ?
This is a conventional name for the first argument of a method


23) Why are strings immutable ?


24) What is the equivalent of a switch / case statement
You can use the match .. case statement


25) There is no GoTo statement


26) Python is case sensitive


27) How to check if Python is installed ?
open command prompt
type "py"


28) What is the ".pyd" file extension ?
This is the equivalent to a "dll" file.


29) Spaces or tabs
The suggested best practice is to use 4 spaces and no tabs


30) There is a module called PyGame


31) How can I declare an optional parameter ?


32) How do I convert a string to a number ?
For integers use the built-in int() type constructor
For floating points use the built-in float() type constructor
Do not use eval()

int ('1') == 1  
float('1') = 1

The number by default are interpreted as a decimal and if it is represented by int('0x1') then it gives an error as ValueError
In this the int(string,base) the function takes the parameter to convert string to number in this the process will be like int('0x1',16) == 16




33) How do I convert a number to a string ?
Use the built-in type constructor str()



34) What is the difference between global and local scope?
A variable created inside a function belongs to the local scope of that function, and can only be used inside that function.
A variable created in the main body of the Python code is a global variable and belongs to the global scope.
Global variables are available from within any scope, global and local.
Global Variables: Variables declared outside a function or in a global space are called global variables. These variables can be accessed by any function in the program.
Local Variables: Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.


35) What is an iterator in Python?
An iterator is an object that contains a countable number of values.
An iterator is an object that can be iterated upon, meaning that you can traverse through all the values.
Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__().


36) What is the __init__() function in Python?
All classes in Python have a function called __init__(), which is always executed when the class is being initiated.
We can use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created.
__init__() is Python's equivalent of constructors in OOP, called automatically when a new object is created. It initializes the object's attributes with values but doesn't handle memory allocation.
Memory allocation is handled by the __new__() method, which is called before __init__().
The self parameter in __init__() refers to the instance of the class, allowing access to its attributes and methods.
self must be the first parameter in all instance methods, including __init__()

class MyClass: 
    def __init__(self, value):
        self.value = value # Initialize object attribute

    def display(self):
        print(f"Value: {self.value}")

obj = MyClass(10)
obj.display()


37) When should you use lambda functions in Python?
Use lambda functions when an anonymous function is required for a short period of time.
A Lambda Function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression.

x = lambda a : a + 10 
print(x(5)) # Output: 15

38) How can you check if all the characters in a string are alphanumeric?
You can use the isalnum() method, which returns True if all the characters are alphanumeric, meaning alphabet letter (a-z) and numbers (0-9).


39) How can you convert a string to an integer?
You can use the int() function, like this:

num = "5" 
convert = int(num)

40) What is indentation in Python, and why is it important?
Indentation refers to the spaces at the beginning of a code line.
Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.
Python will give you an error if you skip the indentation.


41) What is the correct syntax to output the type of a variable or object in Python?

print(type(x)) 

42) Which collection does not allow duplicate members?
Set


43) What is Inheritance in Python?
Inheritance allows us to define a class that inherits all the methods and properties from another class.
Parent class is the class being inherited from, also called base class.
Child class is the class that inherits from another class, also called derived class.


44) What is the output of the following code?

x = 41 
if x > 10:
  print("Above ten,")
  if x > 20:
    print("and also above 20!")
  else:
    print("but not above 20.")

Above ten,
and also above 20!


45) Can you list Python's primary built-in data types, in categories?

Text Type: str 
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview

46) What are Membership Operators?
Membership operators are used to test if a sequence is present in an object. The in and not in operators are examples of these:

x = ["apple", "banana"] 
print("banana" in x) # returns True

x = ["apple", "banana"]
print("pineapple" not in x) # returns True

47) Which statement can be used to avoid errors if an if statement has no content?
The pass statement


48) What are Arbitrary Arguments?
Arbitrary Arguments are often shortened to *args in Python documentations.
If you do not know how many arguments that will be passed into your function, add a * before the parameter name in the function definition.
This way the function will receive a tuple of arguments, and can access the items accordingly.


49) How can you create and use a Module in Python??
To create a module just save the code you want in a file with the file extension .py:

def greeting(name): 
  print("Hello, " + name)
Now we can use the module we just created, by using the import statement:

import mymodule
mymodule.greeting("Jonathan")

50) Can you copy a List in Python by simply writing: list2 = list1?
No, because: list2 will only be a reference to list1, and changes made in list1 will automatically also be made in list2.
To make a copy of a list, you can use copy() or the list() method.


51) How can you return a range of characters of a string?
You can return a range of characters by using the "slice syntax".
Specify the start index and the end index, separated by a colon, to return a part of the string, for example:
Get the characters from position 2 to position 5 (not included):

b = "Hello, World!" 
print(b[2:5])

52) What is a class in Python, and how do you use it?
A Class is like an object constructor, or a "blueprint" for creating objects.
You can create a class with the class keyword:

class MyClass: 
x = 5

Now we can use the class named MyClass to create objects:


53) Create an object named p1, and print the value of x:

p1 = MyClass() 
print(p1.x)



54) What is a Negative Index in Python?
Negative numbers mean that you count from the right instead of the left.
So, list[-1] refers to the last element, list[-2] is the second-last, and so on.


55) How do I modify a string in python?
You can't because strings are immutable in python.
In most situations, you should simply construct a new string from the various parts you want to assemble it from.
Work with them as lists; turn them into strings only when needed.

>>> s = list("Hello zorld") 
>>> s
['H', 'e', 'l', 'l', 'o', ' ', 'z', 'o', 'r', 'l', 'd']
>>> s[6] = 'W'
>>> s
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
>>> "".join(s)
'Hello World'

56) What is the walrus operator ?
This allows you to assign a value to a variable within an expression.
This can be useful when you need to use a value multiple times in a loop, but don't want to repeat the calculation.
This is represented by the `:=` syntax and can be used in a variety of contexts including while loops and if statements.
Added in version 3.8

numbers = [1, 2, 3, 4, 5] 

while (n := len(numbers)) > 0:
    print(numbers.pop())

57) What are Exception Groups in Python?
Added in version 3.11
The ExceptionGroup can be handled using a new except* syntax. The * symbol indicates that multiple exceptions can be handled by each except* clause.
ExceptionGroup is a collection/group of different kinds of Exception.
Without creating Multiple Exceptions we can group together different Exceptions which we can later fetch one by one whenever necessary, the order in which the Exceptions are stored in the Exception Group doesn't matter while calling them.

try: 
raise ExceptionGroup('Example ExceptionGroup', (
TypeError('Example TypeError'),
ValueError('Example ValueError'),
KeyError('Example KeyError'),
AttributeError('Example AttributeError')
))
except* TypeError:
..
except* ValueError as e:
..
except* (KeyError, AttributeError) as e:
..


58) What are Access Specifiers ?
Python uses the '_' symbol to determine the access control for a specific data member or a member function of a class. A Class in Python has three types of Python access modifiers:
Public Access Modifier: The members of a class that are declared public are easily accessible from any part of the program. All data members and member functions of a class are public by default.
Protected Access Modifier: The members of a class that are declared protected are only accessible to a class derived from it. All data members of a class are declared protected by adding a single underscore '_' symbol before the data members of that class.
Private Access Modifier: The members of a class that are declared private are accessible within the class only, the private access modifier is the most secure access modifier. Data members of a class are declared private by adding a double underscore '__' symbol before the data member of that class.


59) Write a code to display the current time?

import time 

currenttime= time.localtime(time.time())
print ("Current time is", currenttime)

60) What is the difference between @classmethod, @staticmethod and instance methods ?
Instance Method operates on an instance of the class and has access to instance attributes and takes self as the first parameter

def method(self): 

Class Method directly operates on the class itself and not on instance, it takes cls as the first parameter and defined with @classmethod.

@classmethod def method(cls): 

Static Method does not operate on an instance or the class and takes no self or cls as an argument and is defined with @staticmethod.
align it and dont bolod anything and not bullet points

@staticmethod def method() 

61) What is PIP?
PIP is an acronym for Python Installer Package which provides a seamless interface to install various Python modules. It is a command-line tool that can search for packages over the internet and install them without any user interaction.


62) What is a zip function?
Python zip() function returns a zip object, which maps a similar index of multiple containers. It takes an iterable, converts it into an iterator and aggregates the elements based on iterables passed. It returns an iterator of tuples.

zip(*iterables) 

63) What are Pickling and Unpickling?
Pickling: The pickle module converts any Python object into a byte stream (not a string representation). This byte stream can then be stored in a file, sent over a network, or saved for later use. The function used for pickling is pickle.dump().
Unpickling: The process of retrieving the original Python object from the byte stream (saved during pickling) is called unpickling. The function used for unpickling is pickle.load().


64) What is a namespace ?
A namespace in Python refers to a container where names (variables, functions, objects) are mapped to objects.
In simple terms, a namespace is a space where names are defined and stored and it helps avoid naming conflicts by ensuring that names are unique within a given scope.
Built-in Namespace - Contains all the built-in functions and exceptions, like print(), int(), etc. These are available in every Python program.
Global Namespace - Contains names from all the objects, functions and variables in the program at the top level.
Local Namespace - Refers to names inside a function or method. Each function call creates a new local namespace.


65) What are Generators ?
the generator is a way that specifies how to implement iterators. It is a normal function except that it yields expression in the function. It does not implement __itr__ and __next__ method and reduces other overheads as well.
If a function contains at least a yield statement, it becomes a generator. The yield keyword pauses the current execution by saving its states and then resumes from the same when required.


66) What are Decorators?
Decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality.
Decorators are often used in scenarios such as logging, authentication and memorization, allowing us to add additional functionality to existing functions or methods in a clean, reusable way.



67) What is the difference between a shallow copy and a deep copy?
Shallow Copy stores the references of objects to the original memory address.
Deep copy stores copies of the object's value.
Shallow Copy reflects changes made to the new/copied object in the original object.
Deep copy doesn't reflect changes made to the new/copied object in the original object.
Shallow Copy stores the copy of the original object and points the references to the objects.
Deep copy stores the copy of the original object and recursively copies the objects as well.
Shallow copy is faster.
Deep copy is comparatively slower.





© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext