1.2.1
Input & Output
Input
Input
There must be some mechanism for the user to input data to the computer.
![Illustrative background for What data can I input?](https://image-v2.cdn.app.senecalearning.com/2018-08/896bfbb3-c1ee-4792-89b4-6bedd4f46136/metadata-data-,h_400,q_80,w_640.jpg)
![Illustrative background for What data can I input? ?? "content](https://image-v2.cdn.app.senecalearning.com/2018-08/896bfbb3-c1ee-4792-89b4-6bedd4f46136/metadata-data-,h_400,q_80,w_640.jpg)
What data can I input?
What data can I input?
- Data can be input from any device connected to the computer.
- The keyboard is the most common data input device for command line programs.
- We will only look at keyboard input in this course.
![Illustrative background for The input function](https://image-v2.cdn.app.senecalearning.com/2018-05/5a9662ab-b70b-4e5b-911b-d70513b89d02/shutterstock_747571558,h_400,q_80,w_640.jpg)
![Illustrative background for The input function ?? "content](https://image-v2.cdn.app.senecalearning.com/2018-05/5a9662ab-b70b-4e5b-911b-d70513b89d02/shutterstock_747571558,h_400,q_80,w_640.jpg)
The input function
The input function
- Python has a built in function (command) which allows us to take keyboard input.
- We can use the code: input(“Prompt”) to take the input.
- We can write any text for the “Prompt”, which will be displayed to the user before they type their response.
- A prompt is a message that is displayed to the user before they type their response.
![Illustrative background for Data type of input](https://image-v2.cdn.app.senecalearning.com/2018-08/6678c24d-96b2-4f4b-8c75-3883dade05bf/corrupted-data-,h_400,q_80,w_640.jpg)
![Illustrative background for Data type of input ?? "content](https://image-v2.cdn.app.senecalearning.com/2018-08/6678c24d-96b2-4f4b-8c75-3883dade05bf/corrupted-data-,h_400,q_80,w_640.jpg)
Data type of input
Data type of input
- When data is entered from the keyboard, it is automatically a ‘string’.
- A string is a sequence of character inputs from the keyboard, for example ‘Hello’.
Output
Output
Output is necessary so that we can see the results of programs.
![Illustrative background for Why do we need outputs?](https://image-v2.cdn.app.senecalearning.com/2018-09/2d01dd30-e1e4-455b-b291-78ae3261cb96/tv-child-watch-boy-,h_400,q_80,w_640.jpg)
![Illustrative background for Why do we need outputs? ?? "content](https://image-v2.cdn.app.senecalearning.com/2018-09/2d01dd30-e1e4-455b-b291-78ae3261cb96/tv-child-watch-boy-,h_400,q_80,w_640.jpg)
Why do we need outputs?
Why do we need outputs?
- Outputs are important so that we can communicate the result of a program to the user.
- Outputs are usually delivered as text onto the screen.
![Illustrative background for The print function](https://image-v2.cdn.app.senecalearning.com/2018-08/2cab83d7-a047-4490-bdf0-ce2e662f6d26/printing-press-print-,h_400,q_80,w_640.jpg)
![Illustrative background for The print function ?? "content](https://image-v2.cdn.app.senecalearning.com/2018-08/2cab83d7-a047-4490-bdf0-ce2e662f6d26/printing-press-print-,h_400,q_80,w_640.jpg)
The print function
The print function
- The output function in Python is called ‘print’.
- The output function ‘prints’ data onto the screen.
- E.g. print(“Hello, world!”) would output the text “Hello, World!”.
![Illustrative background for What data can be outputted?](https://image-v2.cdn.app.senecalearning.com/2018-07/1067548c-e876-492c-a3c9-a8b266f0b1e6/Manipulation-Puppet-Strings-,h_400,q_80,w_640.jpg)
![Illustrative background for What data can be outputted? ?? "content](https://image-v2.cdn.app.senecalearning.com/2018-07/1067548c-e876-492c-a3c9-a8b266f0b1e6/Manipulation-Puppet-Strings-,h_400,q_80,w_640.jpg)
What data can be outputted?
What data can be outputted?
- Output data must be a string before we can print it.
- If we want to display data that is not a string, then we must first cast it to a string.
1Introduction to Python
1.1Python
1.2Input & Output
1.3Data Types
1.4Variables & Constants
1.6Program Flow
2Data Structures
2.1Lists & Strings
2.2File Handling
3Modularity
3.1Subroutines
3.2Data Flow
4Good Practice
4.1Naming & Whitespace
4.2Comments
4.3Exceptions
Jump to other topics
1Introduction to Python
1.1Python
1.2Input & Output
1.3Data Types
1.4Variables & Constants
1.6Program Flow
2Data Structures
2.1Lists & Strings
2.2File Handling
3Modularity
3.1Subroutines
3.2Data Flow
4Good Practice
4.1Naming & Whitespace
4.2Comments
4.3Exceptions
![Go student ad image](/en-GB/revision-notes/_next/image?url=%2Fen-GB%2Frevision-notes%2Fimages%2Fgo-student-uk-ad.jpg&w=640&q=100)
Unlock your full potential with GoStudent tutoring
Affordable 1:1 tutoring from the comfort of your home
Tutors are matched to your specific learning needs
30+ school subjects covered