如果__name__ =='__main__'并设置关键字是什么呢?

时间:2019-11-03 06:26:08

标签: python python-3.x algorithm data-structures

"""
Read file into texts and calls.
It's ok if you don't understand how to read files.
"""
import csv
with open('texts.csv', 'r') as f:
    reader = csv.reader(f)
    texts = list(reader)

with open('calls.csv', 'r') as f:
    reader = csv.reader(f)
    calls = list(reader)


"""
TASK 1:
How many different telephone numbers are there in the records? 
Print a message:
"There are <count> different telephone numbers in the records."
"""


def add_numbers(file: list, tel_numbers: set) -> set:
    """
    Given a file adds all available numbers into a set
    :param file: file containing telephone numbers
    :param tel_numbers: variable used to contain the telephone numbers
    :return: tel_numbers with file numbers extracted
    """
    for column in [0, 1]:
        temp_numbers = [data[column] for data in file]
        tel_numbers.update(temp_numbers)
    return tel_numbers


if __name__ == '__main__':
    tel_numbers = set()

    tel_numbers = add_numbers(calls, tel_numbers)
    tel_numbers = add_numbers(texts, tel_numbers)

    print("There are {} different telephone numbers in the records.".format(len(tel_numbers)))

问题:

我不明白函数中已传递的参数。 -> set def add_numbers(file: list, tel_numbers: set) -> set:中指示的箭头是什么?

也是这一行:

if __name__ == '__main__':
    tel_numbers = set()

0 个答案:

没有答案