presentation on python string manipulation

yanshikasain13 121 views 22 slides Sep 28, 2024
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

This presentation provides an overview of string manipulation in python. This presentation will help beginners to understand basics of python string, also people get a detailed knowledge about accessing string, basic operations, string slices, functions and methods.


Slide Content

CENTRE FOR BIOINFORMATICS PRESENTATION ON : STRING MANIPULATION IN PYTHON SUBMITTED TO: SUBMITTED BY: DR.DEEPSHIKHA YANSHIKA M.SC BIOINFORMATICS ( FINAL)

content Introduction to string Properties of string datatype Basic string creation String concatenation Accessing string through index String slicing Basic functions and methods

Python string A Python string is a datatype that stores sequence of characters. String enclosed within either single quotes (‘ ‘) or double quotes (" "). It is an immutable data type, which means once a string is created, it cannot be modified. However, it is possible to create a new string by concatenating two or more strings.

Properties of String Data Type in Python Immutable:  Strings in Python are immutable, which means that once a string is created, it cannot be modified. Sequence:  Strings in Python are sequences of characters, which means that you can access individual characters in a string using indexing and slicing. Concatenation:  Strings in Python can be concatenated using the + operator. For example, "Hello" + "World" would result in the string "HelloWorld". Methods:  Python provides a range of built-in methods that can be used to manipulate strings, such as the upper() and lower() methods to convert strings to uppercase and lowercase, respectively.

Basic string creation

String concatenation

String concatenation Input Output

Accessing Characters in a String Indexing Indexing allows you to access a specific character in a string by its position. Python uses zero-based indexing, so the first character is at index 0, the second at index 1, and so on. Negative indexing is also supported, where -1 refers to the last character, -2 to the second last, and so forth.

Here’s how you can use indexing to access characters:

Python Program showing string slicing

Positive and negative indexing

Some commonly used string functions in python Case Changing of Python String lower():   Converts all uppercase characters in a string into lowercase. upper():   Converts all lowercase characters in a string into uppercase. title():   Convert string to title case. swapcase ():   Swap the cases of all characters in a string. capitalize() :  Convert the first character of a string to uppercase.

String- lower case to upper case

String-upper case to lower case

Str.title()- converts the first character to the upper case and rest to the lower case.

Str.capitalize()- convert the first character to the uppercase

Str.endswith() – this function return true ,if the given string is ends with the character enclosed within the brackets. str.replace(old,new)- replace old value to the new value. Str.find(word)- return the index of first letter of your desired word. Str.count(substring)- counts the occurrence of substring.