String In Python | Class 11 | Class 12 | CBSE | Computer Science | Informatics Practices | Notes | Study Material | Python Revision Tour

 CHAPTER 10:Strings Manipulation

Introduction

Immutable

A strings are enclosed with ‘ ’,” ”,’’’  ‘’’

A string Object always represents the same string.‘123’,

Python strings are stored in memory by storing individual character in contiguous memory

This sequences of UNICODE character may include a letter,a number,special character,white-space or a backslash

For example:

“Hello Python”

‘Hello Python’

‘’’ Hi Hello Python1234’’’

Creating a string:

A=”Good Morning”

>>>X=”Write article on \”AI\” briefly”

‘Write article on ”AI” briefly’

Empty String

>>>str=”  ”

>>>str

‘ ’

>>>str=’ ’

>>>str

‘ ’

 Multi-line  String:

>>>A=’’’ This is a \

Multi-line String \

Example’’’

>>>A

This is a Multi-line String Example

 Traversing String

Accessing all the elements of the string one after the other by using the subscript or index value.

For example:

S=”HELLO PYTHON”

Positive Index (Forward Index)

0

1

2

3

4

5

6

7

8

9

10

11

(String Variable) S=

H

E

L

L

O

 

P

Y

T

H

O

N

Negative Index(Backward index)

-12

-11

-10

-9

-8

-7

-6

-5

-4

-3

-2

-1

  

>>>S="HELLO PYTHON"

>>>S[0]

'H'

>>>S[3]

'L'

>>>S[-1]

'N'

>>>S[-4]

'T'

Post a Comment

0 Comments