Chapter 9, Working with Various Files

  1. f.readline() reads a single line from the file; a newline character, ( ), is left at the end of the string, and is only omitted on the last line of the file if the file doesn't end in a newline. If you want to read all the lines of a file in a list, you can also use list(f) or f.readlines().
  2. Basically, using with open() just ensures that you don't forget to close() the file, making it safer/preventing memory issues.
  3. r means the string will be treated as raw string.
  4. Generators simplify the creation of iterators. A generator is a function that produces a sequence of results instead of a single value.
  5. The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute. The pass statement is a null operation; nothing happens when it executes.
  1. In Python, an anonymous function is a function that is defined without a name. While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword. Hence, anonymous functions are also called lambda functions.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset