0% found this document useful (0 votes)
1 views29 pages

Powerpoint Python

The document provides an overview of Python programming, covering topics such as variables, operators, input/output functions, conditional statements, loop structures, and jump statements. It explains the syntax and usage of each concept, including examples for clarity. Python is highlighted as a high-level, open-source, and object-oriented language suitable for various applications.
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 views29 pages

Powerpoint Python

The document provides an overview of Python programming, covering topics such as variables, operators, input/output functions, conditional statements, loop structures, and jump statements. It explains the syntax and usage of each concept, including examples for clarity. Python is highlighted as a high-level, open-source, and object-oriented language suitable for various applications.
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/ 29

PYTHON

Content
I. Intro,variables, operators

2. Input / Output function

3. Conditional statement

4. Loop Structure

5. Jump Statements
Introduction
Python is a high level programming language which is open source and
object oriented. It is an interactive language with simple syntax that
allows developers to write robust programs easily and effectively.
Python is an interpreter - based scripting language which can be used:

1. To create web-based applications.


2. To handle large amount of data.
3. To perform complex calculations.
4. To connect to database systems and to read and modify files.
Variables in Python
Variable are named memory locations whose value may change during the
execution of the program. Some rules for naming variables in Python are:

● A variable name can consist of letters, digits and underscore.


● A variable name can start with a letter or an underscore but not with
a digit.
● A variable name cannot have spaces.
● Keywords are not allowed as a variable name.
● Python is case sensitive language, so variable in upper case are
different to those in lower case.
● E.g. A = 15, b2=70, etc
Operators in Python
An operator is a symbol that will perform mathematical operations on variables
or on values. Operators operate on operands (values) and return a result.
Types of Python Operators

Here's a list of different types of Python operators that we will learn in this tutorial.
1.Arithmetic Operators
2. Assignment Operators
3. Relational Operators
4. Logical Operators
Input /Output Function in Python
In Python, the input() and print() functions are commonly used for handling input
and output, respectively.
Input Function - input(): Output Function - print():

The input() function is used to take The print() function is used to


input from the user. It reads a line of display output to the console. It can
text from the user and returns it as a print strings, variables, and
string. Here's a simple example: expressions. Here's an example:
Data Types ( widely used ones)
Input/Output Example :
Conditional Statements
Conditional Statements are features of a programming language, which perform
different computations or actions depending on whether the given condition
evaluates to true or false. Conditional statements in python are of 3 types:

● if statement
● if - else statement
● if - elif - else statement
if Statement
if Statement is used to run a
statement conditionally i.e. if given
condition is true then only the
statement given in if block will be
executed.

Syntax:

If <condition>:
statement(s)
if Statement Example :
if - else Statement
In the case of if - else statement If given
condition is true then the statement given
in if block will be executed otherwise(else)
the statements written in else block will be
executed

Syntax:

if <condition>:
statement(s)

else:
statement(s)
if - else Statement Example :
if - elif - else Statement
if elif is used for execution of statements based on
several alternatives. Python evaluates each condition
in turn and executes the statements corresponding to
the first if that is true. If none of the expressions are
true, and an else clause will be executed
Syntax:

if <condition>:
statement(s)

elif<condition>:
statement(s)

elif <condition>:
statement(s)

else:
statement(s)
if - elif - else Statement Example :
Loop Structure
What Are Python loops?

A loop is an instruction that repeats multiple times as long as some


condition is met.

Type of Loops:

There are mainly two types of loops.

1. FOR … Loop
2. WHILE … Loop

Let’s discuss them one by one.


FOR . . . Loop
The FOR Loop is used in the case where a
programmer needs to execute a part of the code
until the given condition is satisfied. The FOR
Loop is also called a pre-tested loop. It is best to
use for loop if the number of iterations is known
in advance.

SYNTAX:

for variable in range( 0 , NoOfRepetition):

statements(s)
Example
count=0
for count in range(0,10):
print("Hello")

OR

count=0
for count in range(0,10,2):
print("Hello")
WHILE . . . Loop
The WHILE Loop is to be used in situations where
the number of iterations is unknown at first. In
Python, the while loop executes the statement or
group of statements repeatedly while the given
condition is True. And when the condition becomes
false, the loop ends and moves to the next
statement after the loop.

SYNTAX:

while condition:

statements(s)
Example
A=0
while A !=6 :
print(“hello”)
A=A+1

OR

pwd=0
while pwd!=123:
pwd=int(input("Enter Password : "))

print("Password Accepted")
JUMP Statements
As the name suggests, a JUMP Statement is used to break the normal flow of
the program and jump onto a specific line of code in the program if the specific
condition is true.

In simple words, it transfers the execution control of the program to another


statement if a specific condition associated becomes true.

As we proceed further you will get a better understanding of this concept.


Types of JUMP Statements
● BREAK Statement:
A break statement is used to break or stop a flow control. This is generally used in a
loop. A break statement is used in a loop in such a way, that when a particular
condition becomes true, the break statement is executed and we come out of the loop
immediately at that moment.

SYNTAX:
Loop{
Condition:
break
}
Types of JUMP Statements - Break Example

# for loop traversing from 1 to 4


for i in range(1, 5):
# If this condition becomes true break will execute
if(i == 3):
# Break statement will terminate the entire loop
break
print(i)

OUTPUT:

2
Types of JUMP Statements
● CONTINUE Statement:
The continue statement is somewhat similar to the break statement but there is one
significant difference between them. A break statement terminates the entire loop but
the continue statement skips only the current iteration and continues with the rest steps.
So, if we use the continue statement in a loop, it will only skip one iteration when the
associated condition is true and then continue the rest of the loop unlike the break
statement.

SYNTAX:
Loop{
Condition:
Continue
}
Types of JUMP Statements - Continue Example

# for loop traversing from 1 to 4


for i in range(1, 5):
# If this condition becomes true continue will execute
if(i == 2):
# Continue statement will skip the iteration when i=2 and continue
the rest of the loop
continue
print(i)

OUTPUT:

1
3
4

You might also like