Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

Passing Parameters

Passing parameters allows us to send data into a subroutine.

Passing parameters

Passing parameters

  • 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

  • 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

  • Functions are subroutines that return a value.
  • Functions are limited to returning a single value, which is sometimes problematic.
Returning a list

Returning a list

  • One solution to this problem is to use 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

  • In other scenarios, it can be a much better idea to restructure subroutines to return only a single value.
  • Often, multiple return values is a sign of poor program design.
Jump to other topics
1

Introduction to Python

2

Data Structures

2.1

Lists & Strings

2.2

File Handling

3

Modularity

3.1

Subroutines

3.2

Data Flow

4

Good Practice

4.1

Naming & Whitespace

4.2

Comments

4.3

Exceptions

Practice questions on Data Flow

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
Answer all questions on Data Flow

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium