Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what does "yield '\n'" do?
#3
(Jan-30-2018, 09:10 AM)Gribouillis Wrote: yield '\n' generates a string containing a single newline after all the lines have been generated. It is a way to ensure that there is a newline at the end of the file by adding a newline. The if line.strip() test succeeds if it remains anything in the line after removing all the white space at both ends.

Thanks a lot for your explanation!
Reply


Messages In This Thread
what does "yield '\n'" do? - by 2sky - Jan-30-2018, 09:05 AM
RE: what does "yield '\n'" do? - by Gribouillis - Jan-30-2018, 09:10 AM
RE: what does "yield '\n'" do? - by 2sky - Jan-30-2018, 09:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  yield question with append gnomegordon 2 692 Dec-04-2024, 06:47 PM
Last Post: gnomegordon
  yield from akbarza 4 1,737 Apr-19-2024, 07:58 PM
Last Post: DeaD_EyE
  yield usage as statement or expression akbarza 5 2,037 Oct-23-2023, 11:43 AM
Last Post: Gribouillis
  Using list comprehension with 'yield' in function tester_V 5 3,580 Apr-02-2023, 06:31 PM
Last Post: tester_V
  Yield generator weird output Vidar567 8 5,004 Nov-23-2020, 10:59 PM
Last Post: deanhystad
  Trying to access next element using Generator(yield) in a Class omm 2 2,756 Oct-19-2020, 03:36 PM
Last Post: omm
  Yield statement question DPaul 6 3,561 Sep-26-2020, 05:18 PM
Last Post: DPaul
  Problem about yield, please help!! cls0724 5 4,041 Apr-08-2020, 05:37 PM
Last Post: deanhystad
  does yield support variable args? Skaperen 0 2,085 Mar-03-2020, 02:44 AM
Last Post: Skaperen
  generator function that yield from a list buran 9 5,806 Jun-04-2019, 10:26 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020