0% found this document useful (0 votes)
2 views4 pages

Experiment 5

This document outlines Experiment No. 5 for a Python lab, focusing on built-in set and string functions. It includes various Python code examples demonstrating the creation and manipulation of sets and strings. The document concludes with a section for student details and staff signatures.
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)
2 views4 pages

Experiment 5

This document outlines Experiment No. 5 for a Python lab, focusing on built-in set and string functions. It includes various Python code examples demonstrating the creation and manipulation of sets and strings. The document concludes with a section for student details and staff signatures.
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/ 4

EXPERIMENT NO: 5

Name of the Student :-


Roll No. Subject:- Python Lab
Date of Practical Performed :-___________ Staff Signature with Date
&Marks

Title: To study Built-in Set and String functions


Aim: Write python programs to understand Built-in Set and String functions
Theory:
Example
Write python programs to understand Built-in Set functions

# create a set of integer type

student_id = {112, 114, 116, 118, 115}

print('Student ID:', student_id)

# create a set of string type

vowel_letters = {'a', 'e', 'i', 'o', 'u'}

print('Vowel Letters:', vowel_letters)

# create a set of mixed data types

mixed_set = {'Hello', 101, -2, 'Bye'}

print('Set of mixed data types:', mixed_set)


Write python programs to understand Built-in String functions

# Program to find the length of a string

text = "Hello, Python!"

print("Length of the string:", len(text))

# Program to convert a string to uppercase

text = "hello, world"

print("Uppercase string:", text.upper())

# Program to convert a string to lowercase

text = "HELLO, WORLD"

print("Lowercase string:", text.lower())

# Program to remove leading and trailing spaces from a string

text = " Hello, Python! "

print("String without spaces:", text.strip())

# Program to find the position of a substring

text = "Hello, Python!"

position = text.find("Python")

print("Position of 'Python':", position)

# Program to replace a substring with another

text = "I love Python"

new_text = text.replace("Python", "Java")

print("New string:", new_text)


# Program to split a string into a list of words

text = "Hello Python World"

words = text.split()

print("List of words:", words)

# Program to check if a string contains only alphabets

text = "Hello"

print("Is the string alphabetic?", text.isalpha())

# Program to check if the string contains only digits

text = "12345"

print("Is the string all digits?", text.isdigit())

# Program to convert a string to title case

text = "hello, python world"

print("Title case string:", text.title())

# Program to swap the case of each character

text = "Hello, Phcet!"

print("String with swapped case:", text.swapcase())

# Program to capitalize the first letter of the string

text = "hello, Phcet!"

print("Capitalized string:", text.capitalize())


Conclusion:

You might also like