Python Winterr
Python Winterr
Python Winterr
2. readline() Function:
• The readline() function reads a single line from the file.
• If called again, it reads the next line, and so on.
• It stops reading when it encounters a newline character ('\n') or reaches the end of the file.
• It returns the line read as a string, including the newline character at the end.
G) Explain two ways to add objects / elements to list.
Ans) Using the append() Method: The append() method is used to add a single element to the end of a list.It
modifies the original list in place.
Syntax: list_name.append(element)
Using the extend() Method or Concatenation: The extend() method is used to add multiple elements to the
end of a list by extending it with another iterable (like another list). It modifies the original list in place.
Syntax: list_name.extend(iterable)