Grade 11 Exam  >  Grade 11 Notes  >  Computer Science for Grade 11  >  String Manipulation in Python

String Manipulation in Python | Computer Science for Grade 11 PDF Download

Introduction

Python strings are characters enclosed in quotes of any type – single quotation marks, double quotation marks, triple quotation marks.

  • S = ‘Anjeev Singh Academy’ ,    
  • T =  “Singh@123”
  • Mline = ‘‘‘Anjeev Singh Academy

is the best free online academy on YouTube ’’’
Python strings is an immutable data type, i.e. not allowed to change in place. S[0] =‘R’ not allowed

String Indexing – Forward and Backward Indexing in Python

Strings are sequence of characters, where each character has a unique index number.
string = “mycstutorial.in”
>>> string[0]
‘m’
>>> string[-1]
‘n’

Two types of Indexing is supported in python.

  • Forward Indexing and
  • Backward Indexing

The indexes of strings begin from 0 to length-1, in forward direction and  -1, -2, -3, …. , -length in backward direction.

String Manipulation in Python | Computer Science for Grade 11

Strings can be manipulated by using string operators. String operators are

String Manipulation in Python | Computer Science for Grade 11

Traversing a string using loops

Traversing a String or Text means accessing all characters of string, character by character, through its index position.
#Traversal of a string using loop
name = "mycstutorial.in"
for char in name:
print (char, end=' ')

Output
m y c s t u t o r i a l . i n

Traversing a String using index position

#Traversal of a string using index - forward indexing
name = "mycstutorial.in"
for index in range(len(name)):
print (name[index], end=' ')

Output
m y c s t u t o r i a l . i n

#Traversal of a string using index - backward indexing
name = "mycstutorial.in"
for index in range(-1, -len(name)-1, -1):
print (name[index], end=' ')

Output
n i . l a i r o t u t s c y m 

String Slicing

Slice means ‘a part of’.  In Python, string slice refers to a part of string containing some contiguous characters from the string.
Syntax: string[start : end : step]

  • where start and end are integers with legal indices.
  • will return the characters falling between indices start and end. i.e. start, start+1, start+2,…, till end-1.
  • By default value of step is 1. It is an optional argument.

String Manipulation in Python | Computer Science for Grade 11

String Built-in functions

  • Python provides several built-in-methods to manipulate string. 
  • Syntax : stringvariable.methodName( )
  • Example: isalnum(), isalpha(), isdigit(), islower(), isupper(), isspace(), etc

String Manipulation in Python | Computer Science for Grade 11String Manipulation in Python | Computer Science for Grade 11String Manipulation in Python | Computer Science for Grade 11

The document String Manipulation in Python | Computer Science for Grade 11 is a part of the Grade 11 Course Computer Science for Grade 11.
All you need of Grade 11 at this link: Grade 11
84 videos|19 docs|5 tests

Top Courses for Grade 11

84 videos|19 docs|5 tests
Download as PDF
Explore Courses for Grade 11 exam

Top Courses for Grade 11

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Semester Notes

,

practice quizzes

,

Sample Paper

,

Viva Questions

,

shortcuts and tricks

,

Objective type Questions

,

ppt

,

pdf

,

mock tests for examination

,

study material

,

MCQs

,

Previous Year Questions with Solutions

,

Free

,

String Manipulation in Python | Computer Science for Grade 11

,

Summary

,

video lectures

,

past year papers

,

Extra Questions

,

String Manipulation in Python | Computer Science for Grade 11

,

String Manipulation in Python | Computer Science for Grade 11

,

Exam

,

Important questions

;