Entries by Kamal Hussain

Python Unit Testing – Using Mocks

Writing unit tests for programs that have external dependencies is tricky. One approach is mocking external dependencies. For example, if your program is writing to a MySQL database, you may not want to actually write to the database when you run unit tests. Instead, you can use a mock to simulate this operation. Python’s unittest.mock […]

Zero to One – Key Ideas

Looking for a straight talk on the underpinnings of American-style capitalism that make you say, “Ah, now I get it”? “Zero to One” might be the only book you need to read. The essential premise of the book is that creating something new (or going from 0 to 1) is fundamentally different than replicating an […]

Engaging in Dialogue

Engaging in a meaningful dialogue with another person or group of people requires self-awareness, the ability to understand others, and crafting the right communication style. All human beings share common patterns in how they communicate and make decisions. By developing a deeper understanding of the style and motivations of each person, you can engage with […]

Python – For and while loops

Loops are used for repeating an action over and over. If you want to print the numbers from 1 to hundred, one option is using 100 print statements as follows: The above code will have 100 lines. Instead, you can use a loop to do the same. In this example, there are 4 steps: Initialize […]

Python Functions

The main idea of a function is to promote the reuse of the code. Instead of writing all your code in one big file, you can break them down to small chunks and put them in separate functions. As an example, let’s say you want to convert a number from gallons to liters. One option […]

Python Numbers

Python allows three ways to represent numbers. int – whole numbers such as 1, 20, 100000, -3, and 0. float – numbers that have decimal points such as 0.1, 31.2, and -11.2. complex – numbers consists of real and imaginary parts. Examples: 3+5j, 3j, and -2j, where j is the imaginary part. Integers Integers are […]

Python – Getting Started

Python is a high-level scripting language that is easy to learn and can be used for building amazing applications. Jupyter notebook allows you to practice Python on a browser such as Chrome or Safari. Please follow the instructions to get both Python and Jupyter installed on your computer. Windows Installation Python can be installed using […]

Python Strings

Python string is a sequence of characters. Examples of characters are letters (a, b, c etc), digits (1, 2, 3 etc), symbols ($, @, % etc) and even spaces. Following are examples of valid strings: You make a string by enclosing characters in matching single or double quotes. A number or other data types can […]

Python Variables

Python Objects Python objects are like containers that hold data. In Python, every form of data is stored in objects. Normally, you don’t have to worry about how these objects work but for now, just understand that data is stored internally as objects. What is a variable? You can think of a variable as a […]