Searching Strings for Specific Endings/Beginnings : endswith « String « Python Tutorial






import os

for f in os.listdir('C:\\txtfiles'):
    if f.endswith('.py'):
        print "Python file: " + f
    elif f.endswith('.txt'):
        print "Text file: " + f








5.7.endswith
5.7.1.Conditional Execution and the if Statement
5.7.2.Searching Strings for Specific Endings/Beginnings