Docsity

Basics of Programming Part 2, Lecture notes of Programming Languages

Partial preview of the text

Download Basics of Programming Part 2 and more Lecture notes Programming Languages in PDF only on Docsity!

Programming Paradigm

Unit I

Cont.…..

A programming paradigm is a fundamental style, approach or methodology of

programming that dictates how code is structured and organized to solve problems.

Programming Paradigm (Imperative-How to do)

Cont.…..

Unit I

This approach focuses on explicitly detailing the step-by-

step instructions and commands that change the program's

state to reach a goal.

Imperative(How to do)

Structure

Object

Oriented

It focuses on tasks and functions, breaking a program down

into a step-by-step list of instructions or subroutines.

Code is organized around "objects" that

encapsulate both data (attributes) and

behavior (methods).

Differentiate between Structure and Object-Oriented Programming (Homework)

Procedure

Oriented

Code is structured into reusable, sequential

blocks called procedures or functions.

Interpreter Language VS Compiler Language

Interpreter translate and executes the code line by line at runtime.

Compiler translate the entire code at once into machine code before execution.

Interpreter Flow:

Source code

Interpreter(Line-by-line)

Output

Compiler Flow:

Compiler

Execution

Object code

Source code

Interpreter Language VS Compiler Language

Feature Interpreter Language Compiler Language

Translation Translates code line-by-line at runtime.

Translates the entire code at once before

execution.

Execution Program is executed slowly. Program is executed fast.

Error Handling

Errors are shown line-by-line during

execution.

Errors are shown after compilation (once

for the whole program).

Output No separate object code is generated. Generates object code / executable file.

Memory Usage Uses more memory. Uses less memory.

Reusability Code cannot be reused. Object code can be reused.

Portability Platform Independent. Platform Dependent (after compilation).

Examples

Python, JavaScript, PHP, Ruby, Shell

Script, etc.

C, C++, Java, Go, Rust, Fortran, Swift, etc.

Why is Python known as scripting language?

Applications of Python

Python Syntax

Python syntax refers to the set of values that defines how a Python program

is written.

Some Important points

Python is case-sensitive. (Variable and

variable are different)

Python uses indentation (spaces or

tabs) to

define a block of code.

Each statement usually ends with a new

line.

Comments are ignored by the Python

interpreter.

Example:

name = “Python” #variable

Name = “Language” #different variable

print(name) #Python

Comments in Python

A comments is a line or block of text in a program that is ignored by the

Python interpreter. Comments are used to explain the code.

Single-line Comment

This is a single-line comment

print(“Hello”) #print Hello

x = 10 # x is assigned

Multi-line Comment

This is a single-line

comment

It can span across

multiple lines,

Types Syntax

Single-line comments # comments

Multi-line comments

‘ ‘ ‘ comments ‘ ‘ ‘

Or

“ “ “ comments “ “ “

When to use comments?

To explain complex logic.

To make the code more

readable.

To leave notes for yourself

or other developers.

To temporarily disable the

code while testing.

THANK YOU