You are on page 1of 19

CH2.

Python Revision Tour - II


CBSE –CLASS – XII
COMPUTER SCIENCE WITH PYTHON(NEW)
(SUBJECT CODE :083)
Objective 2

Strings in Python
Lists in Python
Tuples in Python
Dictionaries in Python
Sorting- bubble sort & insertion sort
3
Strings in Python 4

Sequence of characters enclosed by single, double or triple quote is


referred as “string”
- ‘Gubert’
- “Gubert”
- ‘’’Gubert’’’
String is sequence of characters, each character having unique position
or index
F Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Character W E L C O M E T O I N D I A
BIndex -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
Item Assignment NOT Supported 5
Traversing A String 6

Iterating through a element of String , one character at a time.


Each character are accessible through unique index.
String Operators 7

Basic Operators [ +, *, String Slicing]


Membership Operators [ in , not in]
Comparison Operators [ == , !=, < , <= , >, >=]
Basic Operators (+) 8

+operator is Concatenation Operator


*operator is Replication Operator
Note:
Booth operands must be same type.
Basic Operators (*) 9

+operator is Concatenation Operator


*operator is Replication Operator
Note:
one operand is string and
another must be an integer.
Membership Operators 10

Operator Working
in Returns true if character /substring occurs in a given string, otherwise false.
not in Returns false if character /substring occurs in a given string, otherwise true.
Comparison Operators 11

All relational Operators are comparison operator (<, <=,>, >=,==,!=).


In case of characters Uppercase letters are considered smaller than the
lowercase letters.
Python compares two strings through relational operators using character by
character comparison of their Unicode Values.
Ordinal/ Unicode Value 12
String Slice 13

String slice is the part of a String containing some contiguous


character from thestring.
For Example ‘or’ , ‘corpor’, ‘tion’, ‘n’ are slice of String ‘corporation’.
String Function / Methods 14

Python offers many built-in functions for string manipulation


String Function / Methods 15
String Function / Methods 16
String Function / Methods 17
String Function / Methods 18
H.W Program 19

W.P.P that reads a line and prints its statistics like:


No of Alphabets:
No of Upper Case Alphabets:
No of Lower Case Alphabets:
No of Digits:

Worksheet-2

You might also like