Week 6: BALT 4396b: Learning Python Ch 5-7

Chapter 5: Operators in Python


Last week's (week 5) reading was an introduction to Professor Kelsey's book Learning Python with ChatGPT and Google . Our reading assignment was on chapter's 1-4 where we were introduced to some of the basic/beginner concepts. Those concepts were print statements and comments, indentation, and understanding variables. This week (week 6) our assignment is to read chapters 5-7. These chapters cover other concepts like operators, function in python, and modules. In this blog I'll be focusing more on chapter 5 and giving a quick summary of what it goes over. 

Chapter 5: In chapter 5 we look at operators. Operators are symbols/keywords (a combination of these two) in Python that work to perform operations on variables and values. There are many operators, and they can be broken down into different types or groups. The different types include arithmetic operators, comparison operators, logical operators, and bitwise operators. Let's look further into each one of these and break them down starting with Arithmetic Operators. These are mathematical functions like addition, subtraction, multiplication, and division. Comparison Operators are symbols such as greater than (>) and less than (<), equal (==), not equal (!=). These symbols compare two values and provide a Boolean result of true or false in accordance with the statement. Then there are Logical Operators. Logical operators are also symbols/keywords, but these connect two or more expressions and provide a true or false as well. Bitwise Operators are operations that work with individual bits with binary numbers.

Arithmetic Operator Ex:
# addition
num1 = 10
num2 = 5
result = num1 + num2
print( "The sum of",  num1 , "and" , num2, "is" , result2)

Comparison Operator Ex: 
a = 5
b = 2
print ( 'a == b =' , a == b)
# Output: a == b = False

Logical Operators Ex:
Operator &&
Description: AND
x = 6
y = 3
x < 10 && y >1 Return True

Bitwise Operators Ex: 
Shift Positive Integer
8 >> 1
Transform to binary
0000001000
00000001000
Fill with positive "0" bit
Remove right-most bit

Comments