The basic print function in Python prints a string or a number of characters to standard output - typically the console that you are using to call the program. You can also use it to print these characters in a file. The correct syntax to call the print function depends on the Python version you are using. Print statement
replaced in version 3.x of the family, but still in use in 2.x, the print command is the simplest way to print a string to the console output. "Print" is a special keyword, like "return" and "try." By default, this statement prints the provided object to the standard output. The syntax is as follows:
Print [>> target], [string or character]
By default, Python prints the object, and then prints a line terminator, "\\ n." If you end up with the print statement with a comma, will not print the line terminator. You can also specify a target file to write by using the ">>" string and a comma after the file pointer.
Print Function
the family 3.x version, the print statement has been replaced by the print function introduced in version 2.6 (Reference 1). The print function works like any other function, and you call it with the following syntax:
print ([object, ...] [, sep = ""] [, end = '\\ n'] [, "file = sys.stdout])
All arguments are optional; using no arguments prints a blank line to the console. "September" separates the object components with the given character. "End" specifies the character to print in the end - by default, a newline character, but you can also use an empty string to signify the lack of a new line. Finally, including the "file" parameter allows you to specify a file to write.
Functions also used for printing
Some special functions work in conjunction with the printing functions to provide full functionality to Python. "File.write ()" is a function that writes a string to the given file, calling him to use "sys.stdout" as the file will perform the same function as a print statement or function. "Play (object)" is a function often used in conjunction with a print statement - it converts the given object into a string Print
Examples print
<P. > # Print "Hello, Python!" And a newline character
print "Hello, Python!" # Version 2 onlyprint ("Hello, Python!") # Version 2:03
# Print the contents of the 'arr' array with each entry of the array separated by a comma
print ",". join (arr) # Version 2 onlyprint (arr, sep = "") # Version 2:03
# Print "Hello, Python!" To a file given by the name "fileptr" print >> fileptr "Hello, Python!"; # Version 2 onlyprint ("Hello, Python", file = fileptr) # Version 2:03
replaced in version 3.x of the family, but still in use in 2.x, the print command is the simplest way to print a string to the console output. "Print" is a special keyword, like "return" and "try." By default, this statement prints the provided object to the standard output. The syntax is as follows:
Print [>> target], [string or character]
By default, Python prints the object, and then prints a line terminator, "\\ n." If you end up with the print statement with a comma, will not print the line terminator. You can also specify a target file to write by using the ">>" string and a comma after the file pointer.
Print Function
the family 3.x version, the print statement has been replaced by the print function introduced in version 2.6 (Reference 1). The print function works like any other function, and you call it with the following syntax:
print ([object, ...] [, sep = ""] [, end = '\\ n'] [, "file = sys.stdout])
All arguments are optional; using no arguments prints a blank line to the console. "September" separates the object components with the given character. "End" specifies the character to print in the end - by default, a newline character, but you can also use an empty string to signify the lack of a new line. Finally, including the "file" parameter allows you to specify a file to write.
Functions also used for printing
Some special functions work in conjunction with the printing functions to provide full functionality to Python. "File.write ()" is a function that writes a string to the given file, calling him to use "sys.stdout" as the file will perform the same function as a print statement or function. "Play (object)" is a function often used in conjunction with a print statement - it converts the given object into a string Print
Examples print
<P. > # Print "Hello, Python!" And a newline character
print "Hello, Python!" # Version 2 onlyprint ("Hello, Python!") # Version 2:03
# Print the contents of the 'arr' array with each entry of the array separated by a comma
print ",". join (arr) # Version 2 onlyprint (arr, sep = "") # Version 2:03
# Print "Hello, Python!" To a file given by the name "fileptr" print >> fileptr "Hello, Python!"; # Version 2 onlyprint ("Hello, Python", file = fileptr) # Version 2:03