► Python program to accept a filename from the user and print the extension of that


Steps followed:
1. get the filename with extension from the user and store it in variable filename
2. split filename based on .(dot) and store in variable sep
3. get the last value from the sep list i.e. the file extension
4. print the file extension


Program

#Python program to accept a filename from the user and print the extension of that

# get the filename with extension from the user and store it in variable filename
filename = input("enter complete filename with extension :")

# split filename based on .(dot) and store in variable sep
sep = filename.split(".")

#get the last value from the sep list i.e. the file extension
extn = sep[-1]

#print the extension
print("extension of the filename %s is %s"%(filename,extn))


Output

enter complete filename with extension :output.py
extension of the filename output.py is py


enter complete filename with extension :budget.csv
extension of the filename budget.csv is csv
 

 





Also Read: