Class XI (As Per CBSE Board) : Computer Science
Class XI (As Per CBSE Board) : Computer Science
Class XI (As Per CBSE Board) : Computer Science
Syllabus
2021-22
Chapter 11
Strings
Computer Science
Class XI ( As per CBSE Board)
Visit : python.mykvs.in for regular updates
String
Creating String
Creation of string in python is very easy.
e.g.
a=‘Computer Science'
b=“Informatics Practices“
Accessing String Elements
e.g.
('str-', 'Computer Sciene')
str='Computer Sciene' ('str[0]-', 'C')
print('str-', str) ('str[1:4]-', 'omp')
print('str[0]-', str[0]) ('str[2:]-', 'mputer Sciene')
print('str[1:4]-', str[1:4]) ('str *2-', 'Computer
print('str[2:]-', str[2:]) ScieneComputer Sciene')
print('str *2-', str *2 ) OUTPUT ("str +'yes'-", 'Computer
print("str +'yes'-", str +'yes') Scieneyes')
OUTPUT
('Updated String :- ', 'Comp Sc with Python')
Format Symbol
Triple Quotes
It is used to create string with multiple lines.
e.g.
Str1 = “””This course will introduce the learner to text
mining and text manipulation basics. The course begins
with an understanding of how text is handled by python”””
b=‘my comp’;
r=b.split() will be
str.split() Returns list of strings as splitted
[‘my’,‘comp’]
b=‘my comp’;
r=b.partition(‘co
str.partition() Partition the string on first occurrence of substring
mp’) will be
[‘my’,‘comp’]
string=raw_input("Enter string:")
count1=0
count2=0
for i in string:
if(i.isdigit()):
count1=count1+1
count2=count2+1
print("The number of digits is:")
print(count1)
print("The number of characters is:")
print(count2)