Lecture 2
Lecture 2
For example:
Example:
Example:
Example:
2. Converting the string to upper case: a method upper() is used which converts all
the characters to uppercase
3. Converting the string to lower case: a method lower() is used which converts all the
characters to lowercase
5. To reverse a string :
Syntax: string.capitalize()
7. title(): converts the string to the title format by capitalizing first letter of every word
Syntax: string.title()
9. find(): returns the index value of first occurrence of a substring with in specified
begin and end index positions.
10. * operator : * operator with string is used to repeat the occurrences of a string.
when the index value is positive list is accessed from the left side
when the index is negative list is accessed from the right side
A range of data items can be accessed starting from a particular index of a lower value
and ending with an index of higher value.
1. append(): This method inserts the data item to the end of the list.
2. insert(): This method inserts a data item into the specific index value pushing the
existing data items to the right
2. pop(): This method removes(pops) a data item at specified index from the list
4. clear(): This method removes all the data items from the list making it empty.
2. To find the minimum element: Minimum element from the list can be retrieved by
using the method min as according to the following syntax
2. Write a program to count the number of capital letters and display the position of
each capital letter in a user entered string via keyboard
3. Consider two strings, String1 and String2 and display the merged string as output.
The merged string should be the capital letters from both the strings in the order they
appear.
Sample Input:String1:ILikeC String2:MaryLikesPython
Merged string should be ILCMLP
4. Write a program to remove all punctuations like “’!()[]{};:’’’,\,<>,/,?,@,#,$,
%^&*_~” from the string provided by the user.
5. Write a binary search function which searches an item in a sorted list. The function
should return the index of element to be searched in the list.
28/10/2023 Dr. Sannidhan M Shetty 34
Lab Questions
6. Write a python program to create two separate lists of integers. List elements of both
the list shall be read from keyboard input. Program should display “Lists are
symmetrical” if both the lists contain equal number of even and odd numbers.
7. Write a function that returns the index of the smallest element in a list of integers. If
the number of such elements is greater than 1,return the smallest index. Use the
following header: def indexOfSmallestElement(lst): Write a program that prompts
the user to enter a list of numbers, invokes this function to return the index of the
smallest element and displays the index