0% found this document useful (0 votes)
5 views

Python strings

Uploaded by

gagotiasushant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python strings

Uploaded by

gagotiasushant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python Training

Python Strings

- Aafiya Noorian Khan


Sequences in Python
• Strings
• Lists
• Tuples
• Sets
• Dictionary
Strings In Python

• Strings are sequences of characters, enclosed within single or double quotation


marks.
Example : ‘name’ and “name” are same

• We can display string using print() function


Example : print(‘hi’)

• we can Assign string to a variable

• Python does not have character data type , a single character is simply a string
with length of 1.
Indexing , Repetition , Slicing in Strings
• Indexing is a concept of reaching out to a particular character in a string.

• Repetition can be performed by using ‘*’ operator.

• Slicing returns range of characters by using the slice syntax. We need to specify
start index and end index separated by a colon, to return part of the string.

• Step value can also be passed to slices.

• Length of string is found using len().


String Methods
• strip() - removes any whitespace from the beginning or the end.

• find() – It is used to locate substring in given string.

• count() – used to get the occurrences i.e number of times the character occurs.

• replace() – used to replace string, we pass two substrings old and new.

• Strings can be represented in lower(),upper(),title()

• split() – splits the string into substrings if it find instances of the separator.
String Operations

• String membership /checking String

• String concatenation

• We cannot concatenate string with numbers

• Strings are immutable, cannot be changed

• Strings can be deleted using del keyword

You might also like