Skip to main content

Command Palette

Search for a command to run...

Day 6 - Python

👉Operators in Python

Published
3 min read
Day 6 - Python
H

Hemant is a Microsoft certified SharePoint Administrator and Power platform developer with 16+ years extensive experience in IT, Microsoft SharePoint. He has decade involved providing M365 and SharePoint for business problems across nearly all industries and commercial sectors. Also he involved in Management/Leadership of Projects in Energy, Healthcare, Content Management, Mining domain, gaining extensive expertise in Project Lifecycle Management, Agile Development, DevOps Testing Cycle as well as Team Management

• Expertise in all aspects of the SharePoint Administration, installation, configuration, development, architecture, deployment and Migrations

• Experienced in developing collaboration and power platforms, portals, enterprise search, enterprise content management, business processes of SharePoint in large enterprise environments.

• Providing day-to-day administration and support on monitoring, usage and growth analysis and patching on SharePoint intranet and Internet.

• Adopting new technology and implementing them, in-depth functional knowledge with appreciation for technical skills.

• Have been involved in various phases of SDLC including analysis, design, coding, testing and implementation mainly Agile development

• Collaborated in governance development and processes, enhancing system efficiency and adherence to best practice. Improving SharePoint capabilities by evaluating and integrating third-party solutions

Programming and Scripting: Proficient in PnP PowerShell scripting for automation and customization.

Learn more about these cloud projects by visiting my portfolio at https://medium.com/@risbud

Technologies interested Cloud | MultiCloud | AWS | DevOps | Microsoft Azure | Google Cloud | Terraform | Ansible

In this assignment, you will explore various Python operators and their usage. Please complete the following tasks.

✍️Task 1: Arithmetic Operators

  1. Create two variables a and b with numeric values.

  2. Calculate the sum, difference, product, and quotient of a and b.

  3. Print the results.

# Arithmetic operators
a = 6
b = 9
print("Sum a + b:", (a+b) )
print("Sum a - b:", (a-b) )
print("Sum a * b:", (a*b) )
print("Sum a / b:", (a/b) )

Result:

✍️Task 2: Comparison Operators

  1. Compare the values of a and b using the following comparison operators: <, >, <=, >=, ==, and !=.

  2. Print the results of each comparison.

# comparison operators
a = 6
b = 9
print("Result a > b:", (a>b) )
print("Result a < b:", (a<b) )
print("Result a <= b:", (a<=b) )
print("Result a >= b:", (a>=b) )
print("Result a == b:", (a==b) )
print("Result a != b:", (a!=b) )

Results:

✍️Task 3: Logical Operators

  1. Create two boolean variables, x and y

  2. Use logical operators (and, or, not) to perform various logical operations on x and y.

  3. Print the results.

# logical operators
x = -15
y = False
print("Result x and y:", (x & y) )
print("Result x or y:", (x | y) )
print("Result not x:", (not x) )
print("Result not y:", (not y) )


a = 10
b = 10
c = -10

if a > 0 and b > 0:  
    print("The numbers are greater than 0")  

if a > 0 and b > 0 and c > 0:  
    print("The numbers are greater than 0")  
else:  
    print("Atleast one number is not greater than 0") 


a = 37

if not a:  
    print("Boolean value of a is True")  

if not (a%3 == 0 or a%5 == 0):  
    print("10 is not divisible by either 3 or 5")  
else:  
    print("10 is divisible by either 3 or 5")

Results:

✍️Task 4: Assignment Operators

  1. Create a variable total and initialize it to 10.

  2. Use assignment operators (+=, -=, *=, /=) to update the value of total.

  3. Print the final value of total.

# assignment operators
a = 6
b = 9
a += b
print("Result a += b:", a)
a -= b
print("Result a -= b:", a)
a *= b
print("Result a *= b:", a)
a /= b
print("Result a /= b:", a)
a %= b
print("Result a %= b:", a)
a **= b
print("Result a **= b:", a)
a //= b
print("Result a //= b:", a)

Results:

✍️Task 5: Bitwise Operators (Optional)

  1. If you are comfortable with bitwise operators, perform some bitwise operations on integer values and print the results. If not, you can skip this task.
#Bitwise operators
a = 6
b = 9
a += b
print("Result a & b:", (a & b))
print("Result a | b:",  (a | b))
print("Result a ^ b:",  (a ^ b))
print("Result ~a:", (~a))

Results:

✍️Task 6: Identity and Membership Operators

  1. Create a list my_list containing a few elements.

  2. Use identity operators (`is` and is not) to check if two variables are the same object.

  3. Use membership operators (`in` and not in) to check if an element is present in my_list.

  4. Print the results.

# membership operators
weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
days = weekdays
print("days is weekdays: ", (days is weekdays))
a = "hello"
b = "world"
print("a is not b: ", (a is not b))
print("Sunday is in weekdays: ", ("Sunday" in weekdays))
print("Iaitwar is in weekdays: ", ("Iaitwar" in weekdays))
print("Yellow not in weekdays:",  ("Yellow" not in weekdays))
print("Yellow in weekdays:",  ("Yellow" in weekdays))

Results:

Thank you for reading this article/Blog! Happy Learning !!! 👋