• The else clause of the loop is more like the else clause of the try: the else clause of the try is executed when no exception is raised, and the else clause of the loop is executed when no break is run

  • When the first statement inside the function is a string, that string is a docstring, also known as a docString, as described in DocStrings. Docstrings can be used to automatically generate online or printed documents, as well as to allow developers to view documents directly while browsing code. Python developers should get into the habit of adding docstrings to their code

  • A way to determine if there is duplicate data in a list

Method 1: Set method

From collections import Counter def func1(num_list): # Set len(num_list)! =len(set(num_list)): print 'have duplicates!!! ' else: print 'no duplicates!! 'Copy the code

Method 2: Counter class

def func2(num_list): # cou=Counter(num_list) first=cou.most_common(1) # cou=Counter(num_list) first=cou.most_common(1) print 'have duplicates!!! ' else: print 'no duplicates!! 'Copy the code