Source: https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-2-1-data-flow

[Revision notes](https://senecalearning.com/en-gb/revision-notes.md) › [GCSE](https://senecalearning.com/en-gb/revision-notes/gcse.md) › [Coding](https://senecalearning.com/en-gb/revision-notes/gcse/coding.md) › [National Curriculum](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum.md) › Data Flow

# Data Flow

Coding: Introduction to Python v3, topic 3.2.1

## Passing Parameters

Passing parameters allows us to send data into a subroutine.

### Passing parameters

![Passing parameters](https://image-v2.cdn.app.senecalearning.com/2018-09/0013c8a8-e85c-4acd-a8de-79713db7ecab/post-403145_1280.png)

- Passing parameters is the process of passing a piece of data into a subroutine.
- The data is then assigned into a local variable (parameter) inside of the subroutine.
- We can then use this data inside the subroutine.

### Parameters vs global variables

![Parameters vs global variables](https://image-v2.cdn.app.senecalearning.com/2018-08/eeeae8d9-efee-41bc-8e5e-23daff64465b/earth-1617121_1920.jpg)

- We could also pass data by putting it inside of a global variable.
- This is considered bad practice, since it can be accessed by any subroutine.
 Passing parameters is a much more secure, and maintainable approach.

## Returning Multiple Values

Sometimes, a situation might arise where we wish to return multiple pieces of data from the same subroutine.

### Returning values

![Returning values](https://image-v2.cdn.app.senecalearning.com/2018-07/227b3f2c-0edd-4074-9406-bfa10b6e5ef2/Email-Internet-Message-Computer-.jpg)

- Functions are subroutines that return a value.
- In Python, a function can return multiple values. 
 - These values are automatically grouped together (as a tuple).

### Returning a list

![Returning a list](https://image-v2.cdn.app.senecalearning.com/2018-09/3fba2487-0107-4ee7-9e33-50edfe5b6f04/checklist-ticklist-tick-list-.jpg)

- Another solution is to return a list of values.
- We can create a list and append each value we want to return.
- This list can then be returned, containing all of the values.

### Restructuring subroutines

![Restructuring subroutines](https://image-v2.cdn.app.senecalearning.com/courseImages/chemistry/2.3.2%20Giant%20Covalent%20Structures/steel-girder.jpg)

- In some scenarios, it may be better to restructure subroutines so they return a single value.
- Returning multiple values is acceptable when the values are related.
 - If a function returns many unrelated values, it may be a sign that the function should be split into smaller functions.

## Test yourself on Data Flow

- When data is passed as a parameter, it is assigned to what type of variable inside the subroutine?
- Which is the best method to use in Python when multiple related values need to be returned from a function?

[Practise this topic for free](https://app.senecalearning.com/classroom/course/72d0364c-db0a-4630-8e0a-61f48cae0252/section/422971de-7764-4b97-a32b-5c71176b88eb/session)

- Previous topic: [3.1.1 Subroutines](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-1-1-subroutines.md)
- Next topic: [4.1.1 Identifiers](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-1-identifiers.md)

## Coding: Introduction to Python v3 contents

### 1 Introduction to Python
- 1.1 Python
  - [1.1.1 Python](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-1-1-python.md)
- 1.2 Input & Output
  - [1.2.1 Input & Output](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-2-1-input-and-output.md)
- 1.3 Data Types
  - [1.3.1 Data Types](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-3-1-data-types.md)
- 1.4 Variables & Constants
  - [1.4.1 Variables & Constants](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-4-1-variables-and-constants.md)
- 1.5 Operators
  - [1.5.1 Arithmetic & Relational Operators](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-1-arithmetic-and-relational-operators.md)
  - [1.5.2 Boolean & Assignment Operators 2](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-2-boolean-and-assignment-operators-2.md)
- 1.6 Program Flow
  - [1.6.1 Selection](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-1-selection.md)
  - [1.6.2 Iteration](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-2-iteration.md)

### 2 Data Structures
- 2.1 Lists & Strings
  - [2.1.1 Lists](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-1-lists.md)
  - [2.1.2 Strings](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-2-strings.md)
- 2.2 File Handling
  - [2.2.1 File Handling](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-2-1-file-handling.md)

### 3 Modularity
- 3.1 Subroutines
  - [3.1.1 Subroutines](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-1-1-subroutines.md)
- 3.2 Data Flow
  - [3.2.1 Data Flow](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-2-1-data-flow.md)

### 4 Good Practice
- 4.1 Naming & Whitespace
  - [4.1.1 Identifiers](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-1-identifiers.md)
  - [4.1.2 Whitespace](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-2-whitespace.md)
- 4.2 Comments
  - [4.2.1 Comments](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-2-1-comments.md)
- 4.3 Exceptions
  - [4.3.1 Exceptions](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-3-1-exceptions.md)
