Print statement in python takes 5 parameters.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Example: Print name and age in a file separated with | and ending with *
name = 'Your Name'
age = 22print(name,age,sep='|',end='*',file=open('file_path', 'w'), flush=False)
Output:
Your Name|22*
if can also change the default file = sys.stdout as:
import sys
sys.stdout = open('File_Path', 'w')
No comments:
Post a Comment