In this python function program, we will create a function to get the duplicate characters from the string.
What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.
Steps to solve the program
- Create a function dupli.
- Use the def keyword to define the function.
- Pass a parameter i.e. string to the function.
- Create an empty list.
- Use a for loop to iterate over characters from the string.
- Check whether the character appears in the string more than once using count().
- If yes then add it to the empty list.
- Create a set of that list using set().
- Print the output.
- Pass the string to the function while calling the function.
def dupli(string):
list1 = []
for char in string:
if string.count(char) > 1:
list1.append(char)
print(set(list1))
dupli('Programming')
Output :
{'g', 'm', 'r'}
Related Articles
Python function program to get the square of all values in the given dictionary.
Python function program to create dictionary output from the given string.
Python function program to print a list of prime numbers from 1 to 100.
Python function program to get a list of odd numbers from 1 to 100.
Python function program to print and accept login credentials.
Python function program to get the addition with the return statement.