Here I would like to create a sample python program. So you need to open a new window by clicking ctrl+n and save this as “.py” extension. Ex: “hello.py”.
Now type the following code
To execute the above program click on “run” then select “run module”. Otherwise press “F5”.
I/O in python
Using print( )
Printing the output will show you the final result of your code. For this Python has built-in function called print( ) to display the output. We have to notice that there is no semi-colon at the end of statement.
Syntax for print( ) is simple
- To display string.
- If you want to print the value of a variable, then use
- If you want to display both string and variable separate them by a comma and put them within parenthesis.
Using input( )
Python has a built-in function called input( ).This is used to take the input from the user in the string format. String is nothing but a sequence of characters. We can store that input in a variable. You can print it by using the print( ) function.
The syntax for input is quite simple:
- Take an input a string from the user.
- If you want to take input an integer value then