Console Input and Output
Learn how to get user data from standard inputs and display the results on standard outputs or on our console.
We'll cover the following...
Console input and output
Python and PowerShell are both interactive scripting languages that can capture user data from standard inputs and display the results on standard outputs or on our console. In this lesson, we are going to look into some of the approaches and best practices to read and print to PowerShell and Python consoles.
Printing to console
Python provides a built-in function, print(), which by default prints the value passed to the standard output or any other specified stream.
This function is just like the Write-Host or Write-Output cmdlet in PowerShell, which are much simpler and we can directly output strings to the console.
There is a catch, however; Write-Host sends output directly to the console.
Strings inside quotes are sent to a different PowerShell stream called Output stream (the default PowerShell stream). This stream can be piped and used by cmdlets following the pipeline or can be stored in a variable.
Printing without a New-Line
Printing without a new line (essentially, printing without adding a line feed character at the end of the output string) is fairly simple in both PowerShell and Python.
When we don’t want to add a line-feed in PowerShell, we can use the Write-Host cmdlet with a -NoNewLine switch parameter. This will continue printing the item just ...