Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:2024:lab02 [2024/10/12 01:28]
stefan.sterea
lfa:2024:lab02 [2024/10/12 01:40] (current)
stefan.sterea
Line 279: Line 279:
 The program will be interpreted even if ''​Void''​ does not correctly implement the methods in ''​Tree''​ (though there are ways to enforce it at runtime. See [[https://​blog.teclado.com/​python-abc-abstract-base-classes/​|here]]). The program will be interpreted even if ''​Void''​ does not correctly implement the methods in ''​Tree''​ (though there are ways to enforce it at runtime. See [[https://​blog.teclado.com/​python-abc-abstract-base-classes/​|here]]).
  
-The class constructor is the ''​__init__(self):''​ method. Also note the mandatory presence of ''​self'',​ which is the Python equivalent of ''​this''​. Each method will receive the object it is called on as the first argument.+The class constructor is the ''​%%__init__(self):​%%''​ method. Also note the mandatory presence of ''​self'',​ which is the Python equivalent of ''​this''​. Each method will receive the object it is called on as the first argument.
  
-The method ''​def __str__(self):''​ is the Python equivalent for ''​toString()''​. An object can be displayed using the function ''​str''​.+The method ''​%%def __str__(self):​%%''​ is the Python equivalent for ''​toString()''​. An object can be displayed using the function ''​str''​.
  
 ===== The functional style ===== ===== The functional style =====
Line 368: Line 368:
  
   * for functions/​methods:​ ''​def <​func_name>​([<​param>:​ <​type>,​ ...]) -> <​return_type>''​   * for functions/​methods:​ ''​def <​func_name>​([<​param>:​ <​type>,​ ...]) -> <​return_type>''​
-  * you can also type a variable with ''​Callable[ [<​param_type1>,​ ...], <​return_type>​]''​ to hold functions or lambdas+  * you can also type a variable with ''​%%Callable[[<​param_type1>,​ ...], <​return_type>​]%%''​ to hold functions or lambdas
  
 <code python> <code python>
Line 412: Line 412:
   * list[type], set[type], frozenset[type],​ dict[key_type,​ val_type]: basic data collections   * list[type], set[type], frozenset[type],​ dict[key_type,​ val_type]: basic data collections
   * * ''​Any'':​ a type is compatible with any other type (if no type hint is specified, this is what type checkers usually default to)   * * ''​Any'':​ a type is compatible with any other type (if no type hint is specified, this is what type checkers usually default to)
-  * ''​Callable[ [<​param_types>​...],​ <​return_type>​]'':​ this defines a function with a given signature+  * ''​%%Callable[[<​param_types>​...],​ <​return_type>​]%%'':​ this defines a function with a given signature
   * ''<​type1>​ | <​type2>'':​ the ''​|''​ operator allows us to indicate that a given object can be one of two(or more) types   * ''<​type1>​ | <​type2>'':​ the ''​|''​ operator allows us to indicate that a given object can be one of two(or more) types
   * ''​None'':​ represents the lack of a value (or an explicit None value); useful to mark functions which have no return value, or that a value may be purposefully missing (in combination with the ''​|''​ operator), and a None check may be necessary   * ''​None'':​ represents the lack of a value (or an explicit None value); useful to mark functions which have no return value, or that a value may be purposefully missing (in combination with the ''​|''​ operator), and a None check may be necessary
   * The official typing documentation [[https://​docs.python.org/​3/​library/​typing.html|here]]   * The official typing documentation [[https://​docs.python.org/​3/​library/​typing.html|here]]
  
-==== Practice ====+===== Practice ​=====
  
 The task of this lab will be to implement the accepting procedure of a DFA in Python, in order to get familiar with Python'​s language constructs and get a start into working with DFAs in code. The task of this lab will be to implement the accepting procedure of a DFA in Python, in order to get familiar with Python'​s language constructs and get a start into working with DFAs in code.