Код: Выделить всё
def func1(list1):
a = 1
func1_result = []
func1_result = list1 * a # This is just an illustrative example to show the function returns any list.
return func1_result
Пример 1:
Код: Выделить всё
list1_1 = [5, 4, 3, 2, 1]
print(f"{func1(list1_1)}") # "[5, 4, 3, 2, 1]"
Пример 2:
Код: Выделить всё
list1_1 = [5, 4, 3, 2, 1]
print(f"{func1(list1_1)[0]}") # "5"
Код: Выделить всё
def func1(list1):
a = 1
func1_result = []
'''
if the funcion calling instruction is about getting the whole resulting list:
do the calculations to get the whole resulting list.
elif the funcion calling instruction is about getting one specific index value of the resulting list:
do the calculations to get only the resulting value for the specified index.
# In this case the result could be a 1-element list.
# Main goal in these kinds of cases: saving memory during calculations when working with large lists and with many function's calls.
'''
return func1_result
Подробнее здесь: https://stackoverflow.com/questions/793 ... -could-det