Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

print >> trong Python làm gì?


print >> cú pháp mở rộng statement print chuẩn để in vào bất kỳ file-like object nào, thay vì mặc định sys.stdout. Dùng in trực tiếp ra file.

Ví dụ

Mở file my_file, ghi vào nó:

>>> my_file = open("my_file")
>>> print >>my_file, "Hello World"

Sẽ ghi "HelloWorld" vào my_file. Cũng dùng với file-like objects khác.