0% found this document useful (0 votes)
50 views

Fundamentals of Programming

Uploaded by

nyxaintbad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Fundamentals of Programming

Uploaded by

nyxaintbad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 90

Fundamentals of

Programming
AN INTRODUCTION TO COMPUTER PROGRAMMING
AND PYTHON
What is Computer Program?

 a collection of instructions that can be executed by


a computer to perform a specific task or set of tasks.
What is Computer
Programming?

 the process of designing and creating programs


 written in a programming language
 is a formal language that specifies a sequence of
operations for the computer to follow
 Examples: Python, Java, C++, etc.
Computer
Programming
Process
Computer Programming Process

The 3-Step process


Running Code

 Compiled Language: Compile then Run

 Interpreted: Run
Evaluating Results

Three possible outcomes after evaluation stage:


1. Correct results
2. Errors
3. Incorrect results

 Errors
Occur when our code attempts to do something it isn’t allowed to do.
 Incorrect results
Code run successfully, but do not do what we want/expect it to do.
WHAT ARE THE
Execution PROCESSES THAT THE
CODE UNDERGOES
model BEFORE IT CAN BE
RUN(EXECUTED)
Execution Model

Interpreted vs. Compiled:


• Interpreted Languages: Code is executed line-by-line
by an interpreter (e.g., Python, JavaScript).
• Compiled Languages: Code is translated into machine
code by a compiler before execution (e.g., C, C++).
Just-In-Time (JIT) Compilation: A hybrid approach
where code is compiled at runtime (e.g., Java, C#).
Compilation

Compilation: The overall process of translating a high-level


programming language (such as C, C++, or Java) into
machine code that can be executed by a computer's CPU.
This involves several intermediate steps and
transformations.
Compilation
Compilation

1.High-Level Program:

Format: Source code written in a high-level language (e.g., C, C++, Java).


Compilation

2. Compiler
Role: Translates high-level source code into an intermediate representation (IR). This step involves
syntax and semantic analysis.

Output: Intermediate Representation (IR).

A lower-level, platform-independent code used for optimization and transformation.


Compilation

3. Optimization Passes

Role: Translates high-level source code into an intermediate representation (IR). This step involves
syntax and semantic analysis.

Role: Improve the IR by optimizing performance and reducing the code size.

Output: Optimized Intermediate Representation (IR).


An optimized version of IR that's closer to machine code.
Compilation

5. Code Generation
Role: Converts the lower-level IR into assembly code, which is specific to a given CPU architecture.

Output: Assembly Code.

Human-readable low-level instructions for the CPU.


Compilation

6. Assembler
Role: Translates assembly code into machine code (binary code).
Output: Machine Code.

Binary code that the CPU can execute directly.


Compilation

7. Executable File
Format: The final output that contains machine code and can be executed by
the operating system.

Example: A file with a .exe extension on Windows or an ELF file on Linux.


Interpretation

Interpretation refers to the process of executing a high-level


program directly, line by line or statement by statement, without
first translating it into machine code. Instead of converting the
entire program into machine code before execution, an interpreter
processes the source code on the fly.
Interpretation

1. Source Code

Format: High-level source code (e.g., Python, JavaScript).


Interpretation

2. Interpreter

Role: Executes the source code directly. The interpreter reads the code, parses it, and performs the
instructions in real-time.
Output: Direct execution of commands without producing intermediate machine code.
Interpretation

3. Execution
The interpreter translates each line of code into an internal representation and
then executes it immediately.
This process is repeated for each statement or line of code in the program.
3.3 Compilation & Interpretation Summary

Key Characteristics of Interpretation

Real-Time Execution: The program is executed line by line or statement by statement.

No Intermediate Machine Code: Unlike compilation, interpretation does not generate machine code.

Instead, it directly interprets and executes the source code.

Slower Execution: Since the source code is processed in real-time, interpretation can be slower compared to compiled
machine code execution.

Ease of Debugging: Easier to debug due to the ability to execute code incrementally and test parts of the program
interactively.

Example of Interpreters

Python Interpreter: Executes Python code directly without needing a separate compilation step.
JavaScript Engine: In web browsers, JavaScript is interpreted to execute scripts on the client side.
3.3 Compilation vs Interpretation vs JIT

Interpretation involves reading and executing high-level code directly, without translating it into machine
code beforehand.

Compilation translates the entire high-level program into machine code before execution, which is then run
by the CPU.

In some modern programming environments, a combination of both techniques is used. For instance, many
languages use Just-In-Time (JIT) compilation, where an interpreter compiles code to machine code at
runtime to optimize performance while maintaining some of the benefits of interpretation.

In compiled languages, the entire program is converted into machine code before execution. This means
that the compilation process occurs first, producing an executable file that can be run on the target
machine.

In interpreted languages, the code is executed line by line. Each line is parsed, interpreted, and converted
to machine code on-the-fly during execution. This means that there is no separate executable file produced
beforehand; instead, the interpreter processes the code directly.

In JIT compilation, the interpreter initially executes the program in a way similar to a traditional interpreter,
scanning the code to identify "hotspots" (frequently executed sections) that are candidates for optimization.
These hotspots are compiled into machine code on-the-fly during execution, which can lead to
performance improvements compared to purely interpreted execution.
THE SET OF RULES THAT
DEFINES THE STRUCTURE OF A
PROGRAM.
SYNTAX SPECIFIES HOW
SYMBOLS, KEYWORDS, AND
OPERATORS SHOULD BE
ARRANGED TO FORM VALID
PROGRAM STATEMENTS.
Syntax
Example:
In Python, the syntax for a
conditional statement is:
if condition:
# do something
THE MEANING OF THE
CONSTRUCTS IN A
PROGRAMMING LANGUAGE.

SEMANTICS DETERMINE WHAT


HAPPENS WHEN A VALID
STATEMENT OR EXPRESSION IS
EXECUTED.
Semantics
THE SEMANTICS OF THE IF
STATEMENT DETERMINE THAT THE
BLOCK OF CODE WILL EXECUTE
ONLY IF THE CONDITION IS TRUE.
Programming
principles
Programming principles

1. KISS (Keep It Simple, Stupid)


Description: Strive for simplicity in design and
implementation. Avoid unnecessary complexity in code,
which makes it harder to understand and maintain.
Goal: Create straightforward solutions that are easy to
read and debug.
2. YAGNI (You Aren't Gonna Need It)
Description: Don’t add functionality until it is necessary.
Avoid building features based on speculative needs.
Goal: Focus on current requirements and avoid over-
engineering.
Programming principles

3. Separation of Concerns
Description: Different concerns or aspects of a program should be separated
into distinct sections. For example, separate business logic from user interface
code.
Goal: Improve modularity, making it easier to manage and update code.
4. Composition Over Inheritance
Description: Favor composing objects with reusable components rather than
relying heavily on inheritance hierarchies.
Goal: Increase flexibility and reduce tight coupling between classes.

5. Principle of Least Astonishment


Description: Software should behave in a way that users expect, avoiding
surprises.
Goal: Enhance user experience by making interfaces intuitive and predictable.
Programming principles

6. Fail Fast
Description: A system should report errors as soon as they are
detected, rather than allowing them to propagate or surface
later.
Goal: Facilitate quicker debugging and identification of issues.
7. Don't Repeat Yourself (DRY)
Description: Avoid duplicating code or logic to minimize
maintenance and improve clarity.
8. Continuous Refactoring
Description: Regularly revisit and improve code, making it cleaner
and more efficient.
Goal: Maintain code quality and adapt to new requirements over
time.
Programming principles

Conclusion
These principles serve as guidelines for writing effective,
maintainable, and efficient code. While they may
sometimes conflict, understanding and applying them
judiciously can lead to better software design and
development practices
A.K.A CODE
ABSTRACTION
- GROUPING OF CODE
Abstraction INTO CALLABLE/
UNITS TO HIDE
COMPLEXITY AND
SIMPLIFY USAGE
Abstraction

 It is also known as code abstraction.


 Abstraction in coding design refers to the practice of hiding
implementation details (the specific code definitions and logic) and
exposing only a simplified representation or interface. This allows users
to interact with the system through higher-level functions or methods,
effectively serving as a reference to the underlying implementation.
 It involves grouping related lines of code that perform a specific task
into a single unit, such as a function, class, or module, and assigning
an identifier (name) to it. This allows you to reference the identifier in
your program to utilize the functionality without needing to understand
the details of how the task is accomplished.
 The abstraction principle can be generalized as the "don't repeat
yourself" (DRY) principle
Abstraction Implementations

Examples:
• Functions: Abstract a sequence of instructions into a callable unit.
• Classes and Objects: Abstract real-world entities into objects with
properties and behaviors.
• Modules/Namespaces serve as a way to group related functions,
classes, and variables, providing a higher-level abstraction for
organizing code. They help manage complexity by encapsulating
functionality and enabling separation of concerns.
• Procedures (or methods, in some contexts) also provide an
abstraction by grouping a series of instructions into a single
callable unit. They are similar to functions but may have a more
specific role in certain programming paradigms, such as
procedural programming, where they might be tied more closely
to the control flow of the program.
THE STYLE OR APPROACH
TO PROGRAMMING
SUPPORTED BY THE
Programming LANGUAGE.(HOW CODE
paradigms ELEMENTS ARE GROUPED
AND HOW THEY CAN BE
REFERENCED OR INVOKED
WITHIN A PROGRAM)
Common Paradigms

Common Paradigms:
❖ Procedural Programming: Focuses on procedures or routines (e.g., C,
Pascal).
❖ Object-Oriented Programming (OOP): Focuses on objects and classes
(e.g., Java, Python).
❖ Functional Programming: Treats computation as the evaluation of
mathematical functions (e.g., Haskell, Lisp).
❖ Event-Driven Programming: Focuses on responding to events or user
actions (e.g., JavaScript).
Procedural Programming

❖ Involves implementing the behavior of a program as procedures


a.k.a functions or subroutines that call each other
Procedural programming is a method of programming that focuses
on writing procedures or routines(e.g., C, Pascal), which are
sequences of instructions that perform a specific task.
This paradigm emphasizes a linear top-down approach to problem-
solving, making it straightforward and easy to understand.
Object-Oriented Programming
(OOP)

❖ Focuses on objects and classes (e.g., Java, Python).


Code grouped into units called “objects”, which are models or real-life
objects.
This objects are sometimes referred to as “class”
Classes can have “properties”, “methods/functions”
i.e. Class Student {
id: string
getSubjects()
}
id is a property; getSubjects() is a method/function of the Student object
Functional Programming

❖ Is a programming paradigm where


computation is treated as the
evaluation of mathematical
functions, avoiding changing state
and mutable data. It emphasizes
the application of functions, often
leading to clearer and more
predictable code.

Much of programming is based around


the idea of “functions”, in some
circumstances referred to as
“methods.”
Functional programming promotes a
declarative style, emphasizing what to
achieve rather than how to achieve it.
Functional Programming
compared to other languages
who use functions
1. First-Class Functions: In functional programming, functions are first-class citizens, meaning they can
be assigned to variables, passed as arguments, and returned from other functions. This allows for a
high degree of flexibility and abstraction.

2. Pure Functions: A pure function is one that, given the same input, will always return the same output
and has no side effects (i.e., it doesn’t modify any external state). This predictability simplifies
reasoning about code and enhances maintainability.

3. Higher-Order Functions: These are functions that can take other functions as arguments or return
functions as results. They enable powerful abstractions and can be used to create reusable code.

4. Immutability: In functional programming, data is often immutable, meaning it cannot be changed


after it's created. Instead of modifying data structures, new versions of them are created. This leads
to fewer bugs related to state changes and makes it easier to reason about code.

5. Function Composition: This concept involves combining simple functions to build more complex ones.
Function composition allows for a more modular approach to programming.

6. Recursion: Functional programming often uses recursion as a primary means of performing repeated
operations, rather than relying on traditional loops. This is due to the emphasis on immutability and
pure functions.
Programming paradigms

❖ Event-Driven Programming: Focuses on responding to events or user actions (e.g.,


JavaScript).
At its core, event-driven programming is centered around the idea of responding to
events. An event can be anything from a user clicking a button, moving the mouse, or
pressing a key, to more complex events like data arriving from a server or a timer
reaching a certain value.
 Key Concepts
1. Events: These are actions or occurrences that your program can respond to.
Examples include user inputs (like clicks or key presses), system events (like a timer
expiring), or even network activity.
2. Event Handlers: These are special functions or methods that you define in your
program. When an event occurs, the associated event handler is executed. Think of
it as a listener that waits for a specific event to happen.
3. Event Loop: This is a core component of event-driven programming. It continuously
checks for events and dispatches them to the appropriate handlers. It keeps the
application responsive by allowing it to handle events asynchronously.
JavaScript is an event-driven programming language that supports Functional
programming
PROGRAMMING
Variables CONCEPTS
Variables

Variables are used to store data that can be manipulated by the


program.
Data Types

Data Types define the kind of data a variable can hold, such as integers, floats,
strings, or Booleans. Understanding how to declare and use variables correctly is
fundamental to programming.
In Python, variable declaration and assignment are simple and straightforward.
Python is dynamically typed, which means you don't need to declare a variable
type explicitly; the type is inferred based on the value you assign to it.
Variable types determine how much memory is required to store the variable’s
value, and memory allocation occurs based on these types when the variable is
declared or initialized
In statically typed languages (like C, C++, and Java), memory is typically
allocated at the time of declaration because the type is known at compile time.
In dynamically typed or interpreted languages (like Python and JavaScript),
memory is allocated when the variable is assigned a value, as the type is inferred
at runtime
Basic Data Types in Python

 Integer (int):Represents whole numbers, both positive and negative, including


zero.
Example: x = 42
Usage: Useful for counting, indexing, and arithmetic operations.

 Float (float):Represents decimal or floating-point numbers.


Example: y = 3.14
Usage: Used in calculations requiring precision, such as scientific computing.
 String (`str`):Represents sequences of characters, enclosed in single, double, or
triple quotes.
Example: name = "Alice" or greeting = 'Hello’
Usage: Used to store and manipulate text, such as names, messages, or user input.
 Boolean (bool):Represents one of two truth values: True or False.
Example: is_valid = True
Usage: Commonly used in conditions and control flow (e.g., if statements) to
evaluate logical expressions.
Variable

Symbolic Name: A variable is identified by a name (identifier) that


represents the data it holds. This name allows programmers to refer to the
variable throughout their code.
Data Storage: Variables store data values that can be of various types,
such as integers, floats, strings, Booleans, and more. The type of data that
a variable can hold often depends on the programming language
being used.
Mutable: The value stored in a variable can be changed during the
execution of a program. This allows programs to manipulate data
dynamically.
Scope: Variables have a scope, which defines where in the code the
variable is accessible. A variable can be local (accessible only within a
certain function or block of code) or global (accessible throughout the
entire program).
Variable Declaration

Variable declaration refers to the process of specifying a variable's name


and its associated data type within a program, using language-specific
keywords (e.g., let or const in JavaScript, or int in C).
This step is critical as it informs the compiler or interpreter of the variable’s
existence and type, ensuring that the program can correctly manage
memory and enforce type constraints.
Without declaring a variable before use, the program would be unable
to allocate the necessary memory or manage its state, leading to
runtime errors or undefined behavior.
Variable Initialization

Variable initialization is assigning a value to a variable for the first time,


ensuring that it has a defined state when used in a program

The main purpose of initialization is to ensure that the variable starts with
a known value, allowing it to be used effectively in computations and
operations from the moment it is defined.

It can occur at the time of the variable’s declaration or later in the code.
* In Python variable declaration and initialization is done at the same
time
Variable naming convention

 In general variable names should have no spaces.


 In Python the Naming convention is as follows:

✓ a variable can have a short name (like x and y) or a more descriptive


name (age, carname, total_volume)
✓ A variable name must start with a letter or the underscore character
✓ A variable name cannot start with a number
✓ A variable name can only contain alpha-numeric(letters, numbers
and an underscore; A to z, 0 to9, and _ ) characters and underscores
✓ Variable names are case-sensitive (age, Age and AGE are three
different variables)
✓ A variable name cannot be any of the Python keywords
Variable Declaration and
Assignment Examples in Python

Variable Declaration and Assignment Examples


1. Basic Variable Declaration and Assignment:
1. You declare and assign a value to a variable in one step.
# Example of integer assignment
age = 25
# Example of string assignment
name = "John Doe"
# Example of float assignment
height = 5.9
# Example of boolean assignment
is_student = True
Variable Declaration and
Assignment

Multiple Variable Assignment:


1. You can assign values to multiple variables simultaneously.
# Assigning values to multiple variables in one line
x, y, z = 1, 2, 3
# Assigning the same value to multiple variables
a = b = c = 100
NOTE:
Given the ff.
x,y=0,1
x,y = y, x+y# here the second x value uses its old value rather that the
value after x=y
is different for the ff:
x=y
y = x+y # here x is now the value of y; so y = x(now 1) + y(which is also 1)
Variable Declaration and
Assignment Examples in Python

Dynamic Typing and Reassignment:


1. Variables can be reassigned to different types of values.
# Initially assigning an integer value
var = 10
print(var)
# Output: 10
# Reassigning the variable to a string value
var = "Hello”
print(var)
# Output: Hello
# Reassigning the variable to a float value
var = 3.14
print(var)
# Output: 3.14
Variable Declaration and
Assignment Examples in Python

Type Annotations (Optional):


Python allows you to use type annotations to indicate the expected type of a variable, but
this is not enforced by the interpreter.
# Using type annotations
name: str = "Alice"
age: int = 30
height: float = 5.5
is_student: bool = False
Uninitialized Variables:
Unlike some languages, Python does not require variables to be declared before
assignment. If you try to use a variable before assigning a value to it, you will get a
NameError.
# This will raise a NameError
print(x)
# Error: NameError: name 'x' is not defined
# Correct usage after assignment
x = 10
print(x)
# Output: 10
These examples illustrate how you can declare and assign values to variables in Python.
The language's flexibility with types and simple syntax make it easy to work with
variables.
Type System

Static vs. Dynamic Typing:


• Static Typing: The type of a variable is determined at compile
time (e.g., C, Java).
• Dynamic Typing: The type of a variable is determined at runtime
(e.g., Python, JavaScript).
• Strong vs. Weak Typing:
• Strong Typing: Types are strictly enforced, and implicit conversions
are limited (e.g., Python, Java).
• Weak Typing: The language performs implicit type conversions
more freely (e.g., JavaScript, PHP).
Data MORE COMPLEX TYPES
structures OF DATA
Data structures

 Primitive Data Structures(Primitive


Types/Basic Types) are the fundamental data
types provided by programming languages,
representing single values without additional structure.
They serve as the building blocks for more complex
data types. Common examples include:
• Integers: Whole numbers without a fractional
component (e.g., int).
• Floating-point numbers: Numbers that can represent
fractions and decimals (e.g., float, double).
• Characters: Individual textual symbols, typically
represented using a character encoding (e.g., char).
• Booleans: Data types representing truth values, such as
true and false (e.g., bool).
Data structures Definition

 Abstract Data Structures(Data Structures/Complex Types) are higher-level


data types constructed using primitive data types. They encapsulate data and
provide methods to manipulate that data, enabling complex operations and more
sophisticated data organization. Some common examples include:
• Arrays: A collection of elements identified by indices, allowing efficient access to
elements at specific positions.
• Linked Lists: A sequential collection of elements (nodes), where each node contains
data and a reference to the next node, enabling dynamic memory allocation and
flexible size.
• Stacks: A collection of elements that follows the Last-In-First-Out (LIFO) principle,
allowing addition and removal of elements only from one end (the top).
• Queues: A collection of elements that follows the First-In-First-Out (FIFO) principle,
allowing addition at one end (the rear) and removal from the other end (the front).
• Trees: A hierarchical structure consisting of nodes, where each node has a value and
zero or more child nodes, facilitating organized data representation and retrieval.
• Graphs: A collection of nodes (vertices) connected by edges, used to represent
relationships and connections between entities, allowing complex traversal and
pathfinding operations.
Operators
Operators

 In programming, operators are special symbols or


keywords that perform operations on one or more
operands (variables, values, or expressions) to
produce a result. Operators are fundamental to
expressing computations, manipulating data, and
controlling program flow. They can be categorized
into several types based on their functionality
Arithmetic Operators

➢ EMDAS (Exponentiation, Python Operators:


Multiplication, Division,
Operator Name Example
Addition, Subtraction)
+ Addition x+y
➢ Modulus – returns - Subtraction x-y
remainder * Multiplication x*y

➢ Div – drops remainder / Division x/y

% Modulus x%y

** Exponentiation x ** y

// Floor division x // y
Relational/Comparison Operators

• Equal to (==): Checks if the values of two operands are equal.

Example: a == b

• Not equal to (!=): Checks if the values of two operands are not equal.

Example: a != b

• Greater than (>): Checks if the value of the left operand is greater than the right operand.

Example: a > b

• Less than (<): Checks if the value of the left operand is less than the right operand.

Example: a < b

• Greater than or equal to (>=): Checks if the value of the left operand is greater than or equal to the right
operand

.Example: a >= b

• Less than or equal to (<=): Checks if the value of the left operand is less than or equal to the right operand.

Example: a <= b
Logical Operators

 Logical AND (and): Returns True if both operands are true.


Example:
a and b
 Logical OR (or): Returns True if at least one of the operands is
true.
Example:
a or b
 Logical NOT (not): Reverses the logical state of its operand.
Example:
not a
Assignment Operators

Assignment (=):
Assigns the right-hand operand to the left-hand operand.
Example: a = b
Add and Assign (+=):
Adds the right-hand operand to the left-hand operand and assigns
the result to the left-hand operand.
Example: a += b
Subtract and Assign (-=):
Subtracts the right-hand operand from the left-hand operand and
assigns the result to the left-hand operand.Example: a -= b
Multiply and Assign (*=):
Multiplies the right-hand operand with the left-hand operand and
assigns the result to the left-hand operand.Example: a *= b
Assignment Operators

Divide and Assign (/=):


Divides the left-hand operand by the right-hand operand and assigns the
result to the left-hand operand. Example: a /= b
Floor Divide and Assign (//=):
Performs floor division on the operands and assigns the result to the left-
hand operand. Example: a //= b
Modulus and Assign (%=):
Takes modulus using two operands and assigns the result to the left-hand
operand. Example: a %= b
Exponent and Assign (**=):
Performs exponential (power) calculation on the operands and assigns the
result to the left-hand operand. Example: a **= b
Operators

Operators
 Others(per language; visit documentation)
Control
structures/
Flow Control
Types of Control Structures

1. Sequential Control
2. Selection/Decision Control (Conditional Statements)
3. Repetition/Looping Control
4. Jump/Branching Control(not in Python)
Algorithms

An algorithm is a step-by-step procedure or formula for solving a


problem or performing a task. It is a sequence of well-defined
instructions that can be followed to achieve a specific goal.
Algorithms are essential in computer science and programming
because they provide a structured approach to problem-solving.
 By studying algorithms, developers can write better programs.
Characteristics of Algorithms

1. Clear and Unambiguous: Each step in an algorithm must be


precisely defined. There should be no ambiguity about what
each instruction means or how to perform it.
2. Well-Defined Inputs and Outputs: An algorithm should specify
the input data it expects and the output it produces. This allows
users to understand what the algorithm requires and what
results to expect.
3. Finiteness: An algorithm must always terminate after a finite
number of steps. It should not run indefinitely; otherwise, it
cannot be considered an effective solution.
4. Effectiveness: Each operation in the algorithm should be simple
enough to be performed in a finite amount of time, using
available resources.
5. Generality: An algorithm should be applicable to a class of
problems, not just a single instance. It should solve the problem
for a range of inputs.
Types of Algorithms

1. Sorting Algorithms: Arrange elements in a specific order (e.g., ascending or


descending). Examples include:
1. Bubble Sort: Repeatedly swaps adjacent elements if they are in the wrong order.
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr

1. Quick Sort: Divides the array into smaller sub-arrays and sorts them.
2. Merge Sort: Divides the array into halves, sorts them, and merges the sorted halves.
Types of Algorithms

Searching Algorithms: Find specific data within a structure. Examples


include:
1. Linear Search: Checks each element one by one until the target is found.
2. Binary Search: Divides a sorted array in half and eliminates half of the
search space until the target is found.
Graph Algorithms: Solve problems related to graph structures. Examples
include:
1. Dijkstra’s Algorithm: Finds the shortest path between nodes in a graph.
2. Depth-First Search (DFS): Explores as far as possible along each branch
before backtracking.
3. Breadth-First Search (BFS): Explores all neighbors at the present depth
before moving on to nodes at the next depth level.
Constant

Data that once set cannot be changed/should not


change
THE IDE: A
IDE PROGRAMMING TOOL
IDE

An Integrated Development Environment (IDE) is a software application


that provides tools for writing, testing, and debugging code all in one
place. Think of it as a "workshop" for programmers.

Using an IDE can make your programming journey smoother and more
enjoyable.
It combines everything you need into one tool, helping you learn and
code more effectively!
Advantages of Using an IDE

1. Easier Coding: IDEs help you write code faster by suggesting what you
might want to type next. This feature is called code completion (a feature
that predicts and suggests code as you type).
2. Debugging Made Simple: If your code has mistakes (called bugs), IDEs
have tools that let you stop the program at certain points (called
breakpoints) so you can see what’s going wrong and fix it. Debugging
(the process of finding and fixing errors in your code) is easier with these
tools.
3. Organized Projects: IDEs help you keep your files organized. Instead of
searching through folders, everything is in one place, making it easier to
manage your projects.
4. Version Control: IDEs often have built-in tools that connect with version
control systems (software that helps manage changes to your code over
time, like Git). This helps you keep track of changes, collaborate with
others, and revert to earlier versions if needed.
Advantages of Using an IDE

5. Automated Builds: When you’re ready to run your code, IDEs can
compile it (convert your code into a program) and check for errors
automatically, saving you time and effort. Build automation (the
process of automatically creating a software build) is a big help.
6. User-Friendly Interface: IDEs have a graphical interface (visual layout
that allows you to interact with the software using buttons and
menus) that is easier to navigate compared to writing everything in a
basic text editor. You can click buttons instead of remembering
complex commands.
7. Customization with Plugins: Many IDEs allow you to add extra features
(called plugins or extensions) to tailor the environment to your needs.
This makes your coding experience more efficient.
Advantages of Using an IDE

8. Supports Multiple Languages: IDEs often support various programming


languages and frameworks (collections of tools and libraries for
building applications), so you can work on different types of projects
without needing different tools.
9. Code Quality Tools: IDEs can analyze your code to help you spot
potential issues and suggest improvements. This process is called
static code analysis (examining code without executing it) and helps
ensure your code is clean and efficient.
10. Built-in Help and Tutorials: Many IDEs come with documentation
(written guides explaining how to use features) and tutorials (step-by-
step guides) that can guide you as you learn, making it easier to
understand new concepts.
Programming Concepts

Portability
The ability of the code to run on different platforms without
modification.
Example: Python is known for its high portability, as Python
programs can run on various operating systems with little or no
change.
Programming Concepts

Performance
How efficiently a language can execute instructions. This includes
factors like speed, memory usage, and the efficiency of compiled
code.
Example: C is known for its high performance, making it suitable for
system-level programming.
Programming Concepts

Memory Management
Automatic vs. Manual Memory Management:
Automatic Memory Management: The language handles
memory allocation and deallocation (e.g., Java, Python).
Manual Memory Management: The programmer is responsible for
managing memory (e.g., C, C++).
Programming Concepts

Concurrency Support
The ability to handle multiple tasks at once, either through multi-
threading or multi-processing.
Example: Java provides built-in support for multi-threading,
while Python offers the threading and multiprocessing modules.
Programming Concepts

Error Handling
Mechanisms to handle runtime errors and exceptions.
Example: Python uses try, except, and finally blocks to
manage exceptions.

Runtime vs Compile time


Programming Concepts

Extensibility
The ability to extend the language with new
features, libraries, or tools.
Example: Python can be extended with C or C++
modules for performance-critical tasks.
Programming Concepts

Libraries and Frameworks


Collections of pre-written code that provide tools
and functions for various tasks, reducing the need to
write code from scratch.
Example: Python has extensive libraries for data
science, web development, and more (e.g., NumPy,
Django).
Programming Concepts

Community Support
The presence of an active community that
contributes to the language's development, provides
resources, and offers help to developers.
Example: Python has a large, active community
with extensive documentation and third-party
libraries.
Programming Concepts

Ease of Learning
How easy it is for beginners to learn and start
programming in the language.
Example: Python is often praised for its simplicity
and readability, making it a popular choice for
beginners.
INTRODUCING PYTHON
Python PROGRAMMING
LANGUAGE
What is Python?

 Brief history and evolution of Python


 Python as a versatile, high-level programming
language
 Key features: simplicity, readability, large standard
library
 Common use cases: web development, data
science, automation, etc.
Why Python?

 Easy to learn and use for beginners


 Extensive libraries and frameworks
 Strong community support
 Cross-platform compatibility
 High demand in the job market
Step-by-Step Guide to Installing
Python

 Download Python from their official website


 Follow steps for installation by the installer
 Verifying the installation
 Open terminal/command prompt
 Type python
 Type print(“Hello Programming!”)
 Enter
 Lookup issues online/ask for help
Integrated Development
Environments (IDEs)

 -Install either of the ff:


 Python IDEs: VS Code, Thonny
 Create file called hello.py
 Type the ff. code in the file:
print(“hello Python IDE!”)
 Save file
 Run file (click triangle icon on the IDE)

You might also like