Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Lesson 3#3

Open
shulzhenkoas wants to merge 16 commits into
mastershulzhenkoas/Python:masterfrom
lesson-3shulzhenkoas/Python:lesson-3Copy head branch name to clipboard
Open

Lesson 3#3
shulzhenkoas wants to merge 16 commits into
mastershulzhenkoas/Python:masterfrom
lesson-3shulzhenkoas/Python:lesson-3Copy head branch name to clipboard

Conversation

@shulzhenkoas

Copy link
Copy Markdown
Owner

ДЗ лекция 3

Comment thread task-3_normal_3.py
# print(new_filter(func, *[-3, -1, 0, 3, 7, -5]))
# а вот это нет:
# print(new_filter(func, [-3, -1, 0, 3, 7, -5]))
# Спасибо. No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Когда ты передаешь [1, 2, 3] в *args, он это видит как 1 аргумент - лист из 3х элементов. Почему бы и нет? Списки такие же равноправные объекты как и просто числа. Попробуй вывести arg в начале new_filter. Увидишь ([1, 2, 3], ). То есть при итерации в 17 строчке - ты итерируешь по кортежу , в котором есть 1 элемент - список. И следом неправильно срабатывает func(), потому что не ожидает на вход получить список.

Чтобы отличить моменты, когда список является аргументом от коллекции аргументов используют символ *

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Доброго времени суток.
если у меня вот такой код:
def new_filter(func_name, *args):
...
digs = [-3, -1, 0, 3, 7, -5]
print(new_filter(func, *digs))
то я получаю на входе функции вот это:
args --> (-3, -1, 0, 3, 7, -5)
type(args) --> <class 'tuple'>

усли же звездочки нет:
def new_filter(func_name, args):
...
digs = [-3, -1, 0, 3, 7, -5]
print(new_filter(func, digs))
то на входе функции вот это:
args --> [-3, -1, 0, 3, 7, -5]
type(args) --> <class 'list'>
Получается "*" меняет список на кортеж.
Зачем это делать я пока что не могу понять.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.