The ChessAIThon project (2025-1-ES01-KA220-VET-000354329) is co-funded by the European Union. The views and opinions expressed in this publication are those of the author(s) only and do not necessarily reflect those of the European Union or the Spanish Service for the Internationalisation of Education (SEPIE). Neither the European Union nor the National Agency SEPIE can be held responsible for them.
Table of Contents
- Role of functions: in a program many checks are performed repeatedly; functions prevent duplication and make the code more readable, easier to test, and easier to extend.
- Definition and call: a function is a block of instructions identified by a name; in Python it is defined with def name(): and an indented body, and it is invoked by writing name().
- Parameters and arguments: parameters in the header make a function reusable with different data; the arguments provided at call time are bound to the parameters by position (order).
- Problem decomposition: it is advisable to split a complex task into small “specialist” functions (e.g., is_null_move, is_on_board, is_rook_move_geometry) and then combine them into a higher-level checking function
- Print() vs return: print() displays values, whereas return sends values back to the caller without printing them
- Scope of a variable: local variables exist only inside a function, while global variables can be read from functions but require the global keyword to be modified.