Python programming:-
What is python
Python is general purpose , dynamically typed, high level language developed by Guido Von Rossum in
the year 1991at CWI in Netherland ;
Features OF Python:-
1) Simple and easy to learn .
2) Freeware and Open Source .
3) Platform independent
4) Rich Library.
5) Portable
6) Embedded
7) Extensible
8) Interpreted
Introduction to Iteration / Iterative Statement :
It allow a set of instructions to be repeated a certain number of times.
Or
It repeats the set of statements until the condition is fulfill
Types Of Loops or Loops In python
1) For Loop
2) While Loop
JUMP STATEMENTS:-
JUMP Statements in Python are used to alter the flow of a loop like you want to skip a part of a loop or
terminate a loop.
Jump statement in Python:-
1) Break Statement
2) Continue Statement
Break & Continue Statements are used to control the flow of loops in python .
1) Break Statement:- “Break” statement is used to exit a loop prematurely when a specific
condition is met.
Break example :-
A= range(8) 0,1,2,3,4,5,6,7,
For x in A
If (x==4):
Break
Print(x)
Output :- 0,1,2,3
2) Continue Statement:- “Continue” statement is used to skip the current iteration of a loop
when a specific condition is met, and it continues with the next iteration of the loop.
Continue example:-
A= range(9) //0,1,2,3,4,5,6,7,8//
For x in A
If (x==7)
Continue
Print(x)
Output:- 0,1,2,3,4 ,6,8
Loop else Statement:-
Or
else with loops:-
While loop with else statements:
Syntax:- while condition
Statement1
Else:
Statement2
Nested Loop ? OR What are nested Loops ?
Python Programming language allows to use one loop
inside another loop.
Syntax:-
While expression :
While expression:
Statement 1
Statement 2
Introduction To Strings:-
- A string is a sequence of characters .
- Strings are Immutable and Ordered .
A=” Hello, World!” A= NITISH
012345
print(A)
len(A)
A [1]
first_string[1]= ‘0’
first_string[1:4]
Traversing a String:-
Traversing a string refers to iterating through the elements
of a string, one character at a time.
For example :-
a = “ARSHLEEN”
for c in a:
Print(c)
OUTPUT:-
A
R
S
H
L
E
E
N
String Operators:- and explain Membership Operators ,
Comparison Operators ?
Python String Methods
Python has a set of built-in methods that you can use on strings. Some of the python
methods are as given below.
1. capitalize()
The capitalize() method returns a string where the first character is upper case, and the
rest is lower case.
Syntax
[Link]()
Example
txt = "arshleen KOUR!"
x = [Link]()
print (x)
Output:
Arshleen kour!
2. upper()
The upper() method returns a string where all characters are in upper case.
Symbols and Numbers are ignored.
Syntax :-
[Link]()
Example
txt = "Arshleen Kour"
x = [Link]()
print(x)
Output
ARSHLEEN KOUR
3. lower()
The lower() method returns a string where all characters are lower case.
Symbols and Numbers are ignored.
Syntax :-
[Link]()
Example
txt = "Arshleen KOUR"
x = [Link]()
print(x)
Output:
arshleen kour