TMC - 9 Digital Tech Semester 2
Toggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto mode

Basic input and output

Output

Python

print("Some text")

C#

Console.WriteLine("Some text")

To print to the console in Python, we use the print() function. In C#, console functions are part of the Console class, and the equivalent to Python’s print function is Console.WriteLine(). If you don’t want it to automatically add a line break, you can use the Console.Write() function.

Input

Python

response = input("What is your name? ")

C#

Console.WriteLine("What is your name? ")
response = Console.ReadLine();

Python’s input() function takes a parameter which is printed, like a question, before reading in the response from the user. C#’s equivalent, Console.ReadLine(), only offers a generic prompt: > . So in order to ask a question or provide information to the user about what they should be entering, you will need to add one or more Console.WriteLine() commands before you read in the user’s response.