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

Python

Python is a high-level, versatile programming language known for its readability and beginner-friendliness, created by Guido van Rossum and released in 1991. It supports various programming concepts such as variables, data types, functions (like print(), type(), and input()), operators, comments, control structures, and iterative statements (for and while loops). The document provides an overview of these concepts, emphasizing their importance in programming with Python.

Uploaded by

Christine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Python

Python is a high-level, versatile programming language known for its readability and beginner-friendliness, created by Guido van Rossum and released in 1991. It supports various programming concepts such as variables, data types, functions (like print(), type(), and input()), operators, comments, control structures, and iterative statements (for and while loops). The document provides an overview of these concepts, emphasizing their importance in programming with Python.

Uploaded by

Christine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

PYTHON

INTRODUCTION
• Examples of programming
language are Python, Java, C, C+
+, etc.
INTRODUCTION
• Examples of programming
language are Python, Java, C, C+
+, etc.
INTRODUCTION
• Python is a high-level programming language.
• Python is:
1. Easy to read
2. Beginner friendly
3. Versatile
4. Portable
5. Community Support
• Python was created by Guido van Rossum, it
was released in 1991.
INTRODUCTION
Python works in two modes:
1. Interactive mode - Interactive mode allows you to execute Python code
line by line, immediately seeing the results.

2. Script Mode - Script mode involves writing Python code in script files
(with a .py extension) and executing them as a whole. This mode is suitable
for writing larger programs.
Variables
• In programming, a variable is a symbolic name that represents a
value stored in the computer's memory.
• Variable rules for Python:
1. Valid Characters
2. Case-Sensitivity
3. Reserved Keywords
4. No Spaces
• It's a good practice to choose descriptive and meaningful variable
names that indicate the purpose or content of the variable. This
makes your code more readable and understandable.
Variables
Valid variable names Invalid variable names

total_marks total marks


year2024 2024year
minvalue min
total.marks
year@2024
Data types
• Data types specify the type of data that a variable can hold.
Python is a dynamically typed language, which means you don't
need to explicitly declare the data type of a variable; Python
automatically assigns the appropriate data type based on the
value assigned to the variable.
• Numeric data types: int, float
• Boolean data type: bool
• Sequence data type: str
Data types
Data type Example

int 176, 4537


float 450.34, 65.89
bool true, false
str “Hello World”
print() function
In Python, the print() function is used to display output to the
console or terminal. It takes one or more arguments, which can
be variables, values, or expressions, and prints them to the
standard output.
Syntax - print(“This is Python”)
type() function
The type() function in Python is used to determine the data type
of a variable or an object. It returns the type of the object passed
as an argument.
Syntax - type(13.24)
input() function
The input() function in Python is used to receive input from the
user via the keyboard. It allows a program to pause execution and
wait for the user to enter some data.
Syntax – a = input(“Enter your name ”)
num = int(input(“Enter a number ”))
Operators in Python
Operators are special symbols or keywords used to perform operations on
variables (operands).
Type Example

Arithmetic operators Addition (+), multiplication (*), Subtraction (-), division (/),
modulus (*), floor division(//), exponential (**)

Relational operators Equal to (==), not equal to (!=), less than(<), greater
than (>), less than equal to (<=), greater than equal to
(>=)
Logical Operators AND (and), OR (or), NOT (not)
Comments in Python
In Python, comments are used to annotate code with explanatory notes. Comments
are ignored by the Python interpreter and do not affect the execution of the program.
There are two types of comments:
1. Single line - Single-line comments begin with the # character and continue until
the end of the line.
Syntax - #This is a single line comment

2. Multi-line comment - For longer comments or documentation strings, you can use
multi-line strings enclosed in triple quotes.
Syntax – “““This is
multi-line
comment”””
Types of control structures
Control structures are used to control the flow of execution of a program
Types of control structures are:
1. Sequential statements - statements that are executed in sequence, one
after the other, in the order in which they appear in the code.
2. Conditional statements - allows you to execute different blocks of code
based on whether a certain condition is true or false.
3. Iterative statements – also known as loops, these statements allow you
to repeat a block of code multiple times.
Conditional Statements
if statement if..else statement if..elif..else

The if statement in Python is a The if..else statement in Python The if..elif..else statement allows
conditional statement that allows is an extension of the if you to specify multiple conditions
you to execute a block of code statement that allows you to and execute different blocks of
only if a specified condition is specify an alternative block of code based on the outcome of
true. code to execute when the those conditions. It provides a
The if statement in Python is a conditional statement that allows you to execute a block of code only if a specified condition
Syntax condition in the if statement way to make decisions with
is true.
if <condition>: evaluates to false. multiple possible outcomes.
statements Syntax Syntax
if <condition>: if <condition1>:
statements statements
else: elif <condition2>:
statements statements
else:
statements
Iterative statements
• Iterative statements, also known as loops, are programming constructs
used to repeat a block of code multiple times.
• Iterative statements reduces the lines of code in a program.
• There are 3 important components of an iterative statement:
1. a start value
2. a condition
3. an increment or decrement statement
• Every loop works with the help of a variable, the control variable
Iterative statements
• Iterative statements, also known as loops, are programming constructs
used to repeat a block of code multiple times.
• Iterative statements reduces the lines of code in a program.
• There are 3 important components of an iterative statement:
1. a start value
2. a condition
3. an increment or decrement statement
• Every loop works with the help of a variable, the control variable
Iterative statements
start value
increment or decrement statement

condition
Iterative Statements
for loop while loop

A for loop is used to iterate over a A while loop allows you to


sequence of elements or a range of repeatedly execute a block of code
values. It allows you to execute a as long as a specified condition is
block of code repeatedly for each true.
item in the sequence. Syntax
Syntax
The if statement in Python while
is a conditional statement that allows condition:
you to execute a block of code only if a specified condition
for item in sequence: is true.statement1
statement1 statement2
statement2
Summary
• A program is a set of instructions that help the computer
perform a task.
• Python is a high-level programming language which is versatile,
portable,
The if statement beginner
in Python friendly,
is a conditional easy
statement that allowstoyouread and
to execute has
a block a good
of code only if a specified condition
is true.
community support.
• A variable is a symbolic name that represents a value stored in
the computer's memory.
• Data types specify the type of data that a variable can hold.
• The print() function is used to display output to the console or
terminal
Summary
• The type() function returns the data type of the variable.
• The input() function is used to get input from the user.
• Operators are special symbols or keywords used to perform operations
on variables
The if statement in Python is(operands).
a conditional statement that allows you to execute a block of code only if a specified condition
is true.
• Comments are used to annotate code with explanatory notes. They are
ignored by the Python interpreter and do not affect the execution of the
program.
• Control structures are used to control the flow of execution of a program
• Conditional statements – if, if…else, if..elif..else
• Iterative statements – for loop, while loop

You might also like