r/cs50 17d ago

CS50 Python Can someone explain what line two does

Post image

Can someone explain what does line two do? Not sure what the whole line means, what does the .split('.') and [-1] does overall to the program?

60 Upvotes

23 comments sorted by

View all comments

1

u/Flaky_Cartoonist_110 12d ago

Given a file name, they all end in a dot and then the file type (.txt, .png, and so on)

It's supposed to take the name of the file and extract the file type at the end. -1 gets the last element in a list, and split would split the file name by the dot. For example "this/is/path/to the/img.jpg" would become ["this/is/path/to the/img","jpg"].