Blog Archives
1 2 3

00: Python dynamic typing, module Vs package and Class Vs Object interview Q&As

Python is a very popular interpreted programming language with the features like strongly typed, dynamically typed, object oriented (i.e. polymorphism, inheritance & encapsulation) & supports functional programming. Also, introduces beginner terminologies like packages, modules, classes, objects, attributes, member variables, class variables, methods & functions. These are are all must-know for beginner level interviews & basic coding tests.

Q1. What do you understand by the term dynamically typed?
A1. There are two types of programming languages: Statically typed (E.g. Java) and dynamically typed (E.g Python) languages. Python is a dynamically typed language meaning that you don’t explicitly have to specify the data type of variables. Dynamic typing means that the type of the variable is determined only during runtime.

Q2. What do you understand by the term strongly typed?
A2. Python is strongly typed, which means variables do have a type and types need to be compatible with respect to the operand when performing operations. For example Python allows one to add an integer and a floating point number, but adding an integer to a string produces error.… Read more ...



01: Python Iterators, Generators & Decorators interview Q&As & Tutorial

Assumes that Python3 is installed as described in Getting started with Python.

1. Iterators

Iterators don’t compute the value of each item when instantiated. They only compute it when you ask for it. This is known as lazy evaluation. Lazy evaluation is useful when you have a very large data set to compute.

Python Iterators have to implement two methods: 1) __next__(self) 2) __iter__(self)

Let’s create a test file with a Main() method.

Read more ...
Tags:

02: Python comprehensions interview Q&As & tutorial

Q. What is a comprehension?
A. Comprehensions are constructs that allow sequences to be built from other sequences. Python 2.0 introduced list comprehensions and Python 3.0 comes with dictionary, set and generator comprehensions.

List Comprehension

Set Comprehension

Given a list return a set.

Dictionary Comprehension

Given a list return a dict.

Generator Comprehension

A generator expression is like a list comprehension, but instead of finding all the items you’re interested and packing them into list, it waits, and yields each item out of the expression, one by one.… Read more ...



03: Python context manager interview Q&As & tutorial

Q. What is a Python context manager?
A. The most common use of context managers is to properly manage resources. Context managers are a way of allocating and releasing some sort of resource exactly where you need it. The simplest example is file access:

Instead of:

The following code ensures that the file handle is closed, but very verbose.

The 11 is the number of bytes written.

Use context manager:

Another example would be in acquiring & releasing thread locks:

Instead of:

Read more ...


04: In Python functions are objects tutorial

Q. Are functions objects in Python? A. Yes. In Python, a function is an object of type function. A function being an object means it is possible to pass a function object around as argument or as return value or to assign another name to the function object. Closures are…

Read more ...


05: Python debugging tutorial

Q. How would you go about debugging Python code? A. Firstly, import pdb

Secondly, use “pdb.set_trace()” where ever you want the execution to pause as shown below with “addition.py” file.

Thirdly, run your code as

When your program encounters the line with pdb.set_trace() it will start tracing….

Read more ...


06: Object introspection in Python tutorial

Q1. What is an Object introspection? A1. It is the ability to determine type & properties of objects at runtime. Everything in Python is an object. Every object in Python may have attributes and methods. Python dir(..) function The dir(..) function returns a sorted list of attributes and methods belonging…

Read more ...


07: Python dictionary tutorial

Q1. What is a dictionary in Python? A1. A dictionary is a general-purpose data structure for storing a group of objects as a set of keys and each key has a single associated value. A value can be a list or list within a list, numbers, etc. A dictionary is…

Read more ...


08: Python Data modelling tutorial – Dunder or Magic Methods, Duck Typing & Protocols

Q1. What is Python data modelling? A1. Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. As an intermediate to experienced Python developer always refer to the Python’s Data model documentation. Q2. What do you understand by the…

Read more ...


09: Python working with String tutorial

Strings in Python can be defined using either single or double quotations as they are functionally equivalent. In addition, it is possible to define multi-line strings using a triple-quote syntax: find() method finds the first occurrence of the specified value. method returns -1 if the value is not found. This…

Read more ...


1 2 3

500+ Enterprise & Core Java programmer & architect Q&As

Java & Big Data Tutorials

Top