Week 6 - BALT 4396 - Learning Python with ChatGPT and Google Colab Chapters 5-7
Operators, Functions, and Modules

Operators
There are multiple types of operators such as arithmetic, comparison, logical, and bitwise and each has its own codes that it can run. Arithmetic operators are focused on addition, subtraction, multiplication, and division while comparison is centered around greater than, less than, and equal to. Additionally, logical operators return true and false statements depending on the code, and bitwise operators return AND/OR statements.
Functions
Functions can be defined as blocks of reusable code that perform a specific task and can be useful in separating larger tasks into more manageable parts.
To define a function, use the def keyword, followed by the function name: def add_numbers(a, b): result = a + b return result
To call a function, use the name followed by parentheses: sum = add_numbers(3, 5) print(sum) # Output: 8
Modules
Modules are files that contain Python code, designated with .py at the end. Usually, they are based on functions, classes, and variables to be used in other Python scripts. Python already has many built-in scripts, however, modules are useful as they can be imported to extend the already existing library.
Built-in Modules:
a. math: Provides mathematical functions like trigonometric, logarithmic, and others.
b. os: Offers a way to interact with the operating system, e.g., file handling, process management.
c. sys: Enables access to system-specific parameters and functions.
d. re: Supports regular expressions for text processing and manipulation.
e. datetime: Supplies classes for working with dates and times.
f. random: Contains functions to generate random numbers.
g. json: Allows encoding and decoding JSON data.
h. collections: Implements specialized container datatypes like namedtuple, defaultdict, and Counter.
Comments
Post a Comment