Python Logical Operators [Blog + Video]

Logical operators work on Boolean values but can be used on integers and other objects as well. Python has three logical operators: and, or, and not. The following table provides a quick overview of Python logical operators: Operator Description Example and Returns True if both operands are True, and False otherwise. (True and True) == … Read more

Python Arithmetic Operators

Arithmetic operators are syntactical shortcuts to perform basic mathematical operations on numbers. Operator Name Description Example + Addition Calculating the sum of the two operands 3 + 4 == 7 – Subtraction Subtracting the second operand from the first operand 4 – 3 == 1 * Multiplication Multiplying the first with the second operand 3 … Read more

Python Comparison Operators [Blog + Videos]

Comparison operators are applied to comparable objects and they return a Boolean value (True or False). Operator Name Description Example > Greater Than Returns True if the left operand is greater than the right operand 3 > 2 == True < Less Than Returns True if the left operand is smaller than the right operand … Read more

Python In-Place Assignment Operators

In-place assignment operators (also called compound assignment operators) perform an operation in-place on a variable provided as first operand. They overwrite the value of the first operand variable with the result of the operation when performing the operator without assignment. For example, x += 3 is the same as x = x + 3 of … Read more

[Review] Learn to Code by Solving Problems – by Prof. Daniel Zingaro

In this article, I’ll review the book “Learn to Code by Solving Problems: A Python Programming Primer” by Prof. Daniel Zingaro. The book is available here: Amazon NoStarch This is an independent review. I didn’t include any affiliate link, so I won’t get compensated if you decide to purchase the book. Although I know Daniel … Read more

Python In-Place Bitwise Left-Shift Operator

Python’s in-place bitwise left-shift operator x <<= y calculates the left-shift operation x << y, and assigns the result to the first operands variable name x. You can set up the in-place left-shift behavior in your own class by overriding the magic “dunder” method __ilshift__(self, other) in your class definition. The expression x <<= y … Read more

Python In-Place Bitwise XOR Operator

Python’s in-place bitwise XOR operator x ^= y calcualtes bitwise XOR x ^ y and assigns the result to the first operand x. To set this up for your own class, override the magic “dunder” method __ixor__(self, other) in your class definition. The expression x ^= y is syntactical sugar for the longer-form x = … Read more

[Cheat Sheet] 6 Pillar Machine Learning Algorithms

This machine learning cheat sheet gives you a visual overview of 6 must-know machine learning algorithms (and where to learn more). Linear Regression: train your linear model to predict output values. K-Means Clustering: apply it on unlabeled data to find clusters and patterns in your data. K-Nearest Neighbors: use a similarity metric to find the … Read more

Logistic Regression in Python Scikit-Learn

Logistic regression is a popular algorithm for classification problems (despite its name indicating that it is a β€œregression” algorithm). It belongs to one of the most important algorithms in the machine learning space. Linear Regression Background Let’s review linear regression. Given the training data, we compute a line that fits this training data so that … Read more

Python In-Place Bitwise Right-Shift Operator

Python’s in-place bitwise right-shift operator x >>= y calculates the right-shift operation x >> y, and assigns the result to the first operands variable name x. You can set up the in-place right-shift behavior in your own class by overriding the magic “dunder” method __irshift__(self, other) in your class definition. The expression x >>= y … Read more

Python In-Place Bitwise AND Operator

Python’s in-place bitwise AND operator x &= y calcualtes bitwise-and x & y and assigns the result to the first operand x. To set it up for your own class, override the magic “dunder” method __iand__(self, other) in your class definition. The expression x &= y is syntactical sugar for the longer-form x = x … Read more

Python In-Place Exponentiation Operator

Python provides the in-place exponentiation operator x **= y that raises x to the power of y using x ** y and assigns the result to the first operands variable name x. You can set up the in-place exponentiation behavior for your own class by overriding the magic “dunder” method __ipow__(self, other) in your class … Read more