Week 6 Assignment

 

Chapter 5: Operators

Python Operators - GeeksforGeeks

Operators in Python are symbols used to perform various operations on variables and values. They can be categorized into several types:

  1. Arithmetic Operators:

    • Addition (+): Adds two values.
    • Subtraction (-): Subtracts the right operand from the left operand.
    • Multiplication (*): Multiplies two values.
    • Division (/): Divides the left operand by the right operand.
  2. Comparison Operators:

    • Equal (==): Returns True if the two operands are equal.
    • Not equal (!=): Returns True if the two operands are not equal.
    • Greater than (>): Returns True if the left operand is greater than the right operand.
    • Less than (<): Returns True if the left operand is less than the right operand.
    • Greater than or equal to (>=): Returns True if the left operand is greater than or equal to the right operand.
    • Less than or equal to (<=): Returns True if the left operand is less than or equal to the right operand.
  3. Logical Operators:

    • and: Returns True if both operands are true.
    • or: Returns True if either of the operands is true.
    • not: Returns True if the operand is false.
  4. Bitwise Operators:

    • Bitwise AND (&): Performs bitwise AND operation on the corresponding bits of the operands.
    • Bitwise OR (|): Performs bitwise OR operation on the corresponding bits of the operands.

Additional operators include:

  • Modulus (%): Returns the remainder of the division.
  • Exponentiation (**): Raises the left operand to the power of the right operand.
  • Floor Division (//): Performs division and returns the largest whole number less than or equal to the result.

Example code demonstrates the use of arithmetic operators like addition, subtraction, multiplication, and division. The output displays the results of these operations.

Chapter 6: Functions in Python

Python Functions - GeeksforGeeks

Functions in Python are blocks of reusable code designed to perform specific tasks. They aid in breaking down complex tasks into smaller, manageable parts and facilitate code reuse. Functions are defined using the def keyword followed by the function name, parentheses, and a colon. Input arguments can be specified within the parentheses, and the function body follows, indented by 4 spaces or a tab. Functions can return a value using the return statement.

Example functions include:

  • A function that adds two numbers and returns the sum.
  • A function that greets a person with a customizable greeting message.

Functions can have default argument values, allowing the function to be called with fewer arguments.

Chapter 7: Modules

Advance Python Modules - How to Create & Import with dir Function -  DataFlair

Python uses a modular approach to organizing code, where modules are files containing Python code, usually with a .py extension. Modules can include functions, classes, and variables, which can be imported and used in other Python scripts.

Built-in modules include math, os, sys, re, datetime, random, json, and collections, among others. Modules can be imported using the import statement, and specific functions, classes, or variables can be imported using the from ... import ... statement. Aliases can be used to shorten module names or avoid naming conflicts.

Example code demonstrates the use of the re module for working with regular expressions to find email addresses in a given text.


Comments

Popular posts from this blog

Week 4: Probability and Statistics for Data

Week 5 Blog Post