Python Interview Qs Flashcards

1
Q

What is Python?

A

high-level, interpreted, strongly and dynamically typed general purpose programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the benefits of Python?

A

Simply, easy to read syntax - reduces the cost of program maintenance.
It is both a scripting and programming language
It’s open source and supports third-party packages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a dynamically typed language?

A

Data types are checked during execution. Python is a strong dynamically typed language - there is no implicit conversion of data types. Python executes each statement line by line and thus type-checking is done on the fly, during execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an interpreted language?

A

Executes statements line by line - Python, JS, R, PHP, Ruby. Program runs directly from source code with no intermediary compilation step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is PEP 8 and why is it important?

A

Official style guidelines for Python Code. Important in open-source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Scope in Python?

A

Every object functions within a scope - block of code where an object is relevant. Defines where objects can be used and in what ways.
Local scope, global scope, module-level scope, outermost scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Local scope

A

local objects available in the current function. Local scope objects can be synced with global scope objects with keyword global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Global scope

A

objects available throughout the code execution since their inception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

module-level scope

A

global objects of the current module accessible in the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

outermost scope

A

all the built-in names callable in the program. Objects in this scope are searched last to find the name reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Difference between lists and tuples

A

Both sequence data types that can store a collection of objects in Python.
Lists are mutable. Tuples are not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Common built-in data types

A

None type
Numeric types: int, float, complex (stores complex numbers in form (A + Bj) and has attr real and imag), bool
Sequence types: list, tuple, range, str, bytearray, bytes, memoryview
Mapping types: dict
Set types: set, frozenset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is pass in Python?

A

null operation used as a placeholder for empty code blocks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Benefits of using modules

A

Simplicity, Maintainability, Reusability, Scoping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are protected attributes?

A

Defined with single underscore prefix. Can be accessed and modified from outside the class they are defined in but a responsible developer should refrain from doing so

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are private attributes?

A

double underscore prefix. Cannot be accessed or modified from outside and will result in AttributeError if attempt is made

17
Q

How can you make a Python Script executable on Unix?

A

script file must begin with
#!/usr/bin/env/python

18
Q

Difference between arrays and lists

A

Arrays can only contain elements of same data type vs lists can contain difference data types (disadvantage of using more memory)

19
Q

How is memory managed in Python?

A

Handled by the Python Memory Manager. Memory is allocated by the manager in the form of a private heap space dedicated to Python. Python objects are stored in heap and since its private, it’s inaccessible to the programmer.
Python has built-in Garbage Collection to recycle the unused memory for the private heap space.