Python
INDEXING FEATURE OF PYTHON
●It will help us to trace down the
elements stored in a form of string
where if u trace down from the left
side the indexing will start from
0,1,2…..n
●If we trace down from the right side
the indexing will start from
-1,-2,-3……n
H E L L O
Left ↑ ↑ ↑ ↑ ↑
Inde
x
0 1 2 3 4
-5 -4 -3 -2 -1 Righ
t
Inde
x
Python Identifier
●It is a name used to identify a
variable ,function,class etc.
●An identifier starts with a
letter A to Z or a to z or an
underscore(_) followed by zero or
more letters,underscores and
digits (0 to 9)
●It does not allow punctuation
characters such as @ , $,and %.
Data types in Python
1.String - group of characters .It can
be a name of a city , animal , or
name of a person.For example -
Jaipur , Dog , Pink etc. It is also
always declared in double quotes
(“”).
name = “Aaradhyey”
2. Int - It will store Integer or
number. For example - 2,4,6,8 etc.
age = 12
3. Long - It will store numeric
values.
age = 4567
4. Float - It will store decimal
values
Height = 5.7 feet
Operators in Python
Operator Description Example
+Addition A = 10
B = 5
Print(A+B)
15
-Subtraction A = 10
B = 5
Print(A-B)
5
*Multiplicati A = 10
on B = 5
Print(A*B)
50
/ Division A = 10
B = 5
Print(A/B) it
will return
quotient
2
Modulus % Print(A%B) it
will return
remainder
0
Floor Division// Return only
integral part
but not the
fractional one
**Exponent Performs 2^5=2*2*2*2*2
exponential = 32
(ower)
calculation on
operators.
Comparison Operator
Let us assume, a = 10 , b = 5
Operator Description Example
== It compares the a==b will return
values false
!=
<>
>
<
>=
Loop
Loop: The set of elements which
execute repeatedly till a particular
condition if satisfied is called loop.
While Loop : A While loop statement
in Python programming language
repeatedly executes a target statement
as long as a given condition is true.
Syntax :
While expression:
statement(s)
For Loop : It has the ability to
iterate over the items of any sequence
such as a list or a string.
Syntax :
For iterating_var in sequence
statement(s)
Example :
For x in range(6):
print(x)
For loop in words
#to access letters given in a words
#using variable
a=”hello”
For a in a:
print(a)
#using direct variable
For b in “hello”:
print(b)
#using input
c=input(“Enter ut name”)
For c in c:
print (c)
Using for loop to extract letters from
given words
1)Greece
2)Library
3)Eucalyptus
4)Hong Kong
5)Jain
Python collections(Arrays)
● List is a collection which is
ordered and changeable.Allows
duplicate members.
● Tuple is a collection which is
ordered and unchangeable.Allows
duplicate members.
● Set is a collection which is
unordered and unindexed,No duplicate
members.
●Dictionary is a collection
List Manipulation
Lists are containers which are used
to store a list of values of any
type.Lists are represented through
square brackets e.g.
[] Represents an empty list
[1,2,3] represents a list of
integers
[‘s’,’p’,’d’] represents a list of
characters
[‘anil’,’suman’,’tarun’] represents
a list of strings.
Indexing in list
To access any item from the list we will use an
indexing feature that means to access elements from
the left side of the list we will start the index
from 0.whereas if you would like to access the last
element of the list u will start the index with
minus 1. For example
digit=[1,2,3,4,5,6,7,8,9,]
List
name=[“mukesh”,”aakash”,”suraj”]
print(names)
names.sort()
print(names)
some=[“zebra31”,”mukesh”,”suraj”]
print(some)
some.sort(Reverse=true)
print(some)