Deutsch English Français Italiano |
<m2le5up2qh.fsf@cochabamba-1.kpn> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Pieter van Oostrum <pieter-l@vanoostrum.org> Newsgroups: comp.lang.python Subject: Re: A technique from a chatbot Date: Wed, 03 Apr 2024 23:15:18 +0200 Lines: 25 Message-ID: <m2le5up2qh.fsf@cochabamba-1.kpn> References: <chatbot-20240402181409@ram.dialup.fu-berlin.de> Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net MWG5iDLBWD5Fv8FvhxHUcg7750S7LZgu3xyjnIYy8HP1F8rj7r Cancel-Lock: sha1:WMt3h8PcZZv+RJJgvr6JFbmhFW0= sha1:IbM++nvx5M8AJpHYmcoZBsK5bZM= sha256:nbI7no8i9fjGsjlpkMvetnbqe9AEnYztG7J0OVDgwxE= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin) Bytes: 1463 ram@zedat.fu-berlin.de (Stefan Ram) writes: > It can lead to errors: > > def first_word_beginning_with_e( list_ ): > for word in list_: > if word[ 0 ]== 'e': return word > something_to_be_done_at_the_end_of_this_function() > > The call sometimes will not be executed here! > So, "return" is similar to "break" in that regard. That can be solved with finally: def first_word_beginning_with_e( list_ ): try: for word in list_: if word[ 0 ]== 'e': return word finally: print("something_to_be_done_at_the_end_of_this_function()") -- Pieter van Oostrum <pieter@vanoostrum.org> www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4]