Python Interview Qs Flashcards
What is Python?
high-level, interpreted, strongly and dynamically typed general purpose programming language
What are the benefits of Python?
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
What is a dynamically typed language?
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.
What is an interpreted language?
Executes statements line by line - Python, JS, R, PHP, Ruby. Program runs directly from source code with no intermediary compilation step.
What is PEP 8 and why is it important?
Official style guidelines for Python Code. Important in open-source
What is Scope in Python?
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
Local scope
local objects available in the current function. Local scope objects can be synced with global scope objects with keyword global
Global scope
objects available throughout the code execution since their inception
module-level scope
global objects of the current module accessible in the program
outermost scope
all the built-in names callable in the program. Objects in this scope are searched last to find the name reference
Difference between lists and tuples
Both sequence data types that can store a collection of objects in Python.
Lists are mutable. Tuples are not.
Common built-in data types
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
What is pass in Python?
null operation used as a placeholder for empty code blocks
Benefits of using modules
Simplicity, Maintainability, Reusability, Scoping
What are protected attributes?
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