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

Ass2 Itw

Uploaded by

shivajirp123
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)
7 views

Ass2 Itw

Uploaded by

shivajirp123
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/ 5

BRACT’s

Vishwakarma Institute of Information Technology, Pune


Practical Implementation Sheet

Department: IT Semester: I Academic Year: 2023-24 Practical No: 2

Class/ Division/ Batch: SY(B)- B2 Roll no:232051 Gr. no: - 222210528

Course: IT WORKSHOP – II Name of Student: Shivaji Rajendra Patil

Aim: Write a program to demonstrate String Manipulation in python and perform: Accessing
Individual Elements, String Operators, String Slices, String Functions and Methods.

Problem Statement: Write a program to count the numbers of characters in the string and
store them in a dictionary data structure.

Theory:

Python String
• A string is a data structure in Python that represents a sequence of characters.
• It is an immutable data type, meaning that once you have created a string, you cannot
change it.
• Strings are used widely in many different applications, such as storing and manipulating
text data, representing names, addresses, and other types of data that can be represented
as text.

print("A Computer Science portal for geeks")

Output:
A Computer Science portal for geeks

Code:

1.Creating the String


#creating string in python
#string with single quote

String1 = 'Hello user'

print(f"String with the use of Single Quotes: {String1} ")

Output:

#double quote

String2 = "All clouds have souls"

print(f"String using Double Quotes: {String2}")

Output:

#Triple quote

String3 = '''The killings were leading the news

in part because of their shocking and

random nature'''

print(f"String using Triple Quotes: {String3}")

print(String3)

Output:
2.Characters of String

#character of string

String4 = "Everything happens for a reason"

# printing first character

print(f"1st character: {String4[0]}")

# printing random character

print(f"6th Character: {String4[5]}")

# printing last character

print(f"Last character: {String4[-1]}")Output:

3.Reversing the String

String5 = "Sheep should sleep in the shed"

print(f"Reversed String: {String5[ : :-1]}")


Output:

4.Slicing

String6 = "She sells seashells by the seashore"

print(f"Initial String: {String6}\n")

print(f"Slicing string from 3-7: {String6[3:7]}\n")

print(f"Characters between 2 to 2nd last: {String6[2:-2]}\n")

Output:

5.String Method

String7 = "Black background, brown background"

print(f"Uppercase String: {String7.upper()}\n")

print(f"Lowercase String: {String7.lower()}\n")

print(f"Using title(): {String7.title()}\n")


Output:

5. Using some other string functions

String8 = "A loyal war\trior will rar\tely worry why we rule."

print(String8.expandtabs(8))

print(f"The least position of 'y': {String8.find('y')}")

Output:

Conclusion: In this way we have demonstrated String Manipulation in python and performed
Accessing Individual Elements, String Operators, String Slices, String Functions and Methods.

Remark: Name of Faculty

Ms. Komal M. Birare Sign:

You might also like