0% found this document useful (0 votes)
3 views

Functions

python - pcep notes exam

Uploaded by

Muthuu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Functions

python - pcep notes exam

Uploaded by

Muthuu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

**Functions:**

- Parameters are defined within a function, while arguments are provided outside
of it.
- Positional arguments cannot appear after keyword arguments (e.g., `def
func(a=1, b=2, c)` is incorrect, while `def func(c, a=1, b=2)` is correct).
- Recursive functions call themselves during execution.
- Attempting to use a function before its definition results in a `NameError`.
- `None` is not considered a value and should not participate in expressions.
- `None` can be assigned to variables or returned as a result of a function.
- `None` can be used in comparisons to check a variable's state.
- If a function does not explicitly return a value using `return`, it implicitly returns
`None`.
- Variables declared outside functions are accessible within function bodies
unless a local variable of the same name is defined inside the function.
- Variables defined inside a function are scoped only to that function.

**Additional Concepts:**

1. Tuples, as sequence types, can be indexed and sliced like lists.


2. The `copy()` method creates a separate memory reference for the copied
object.
3. `list.reverse()` reverses a list in place.
4. Stacks follow the LIFO (Last In, First Out) principle.
5. In dictionaries, `1` and `1.0` are treated as the same key.
6. Function parameters are special variables that can be accessed within the
function.
7. Code within an `except` block runs if an error occurs in the `try` block. Place
code that may raise an exception in `try`.
8. `None` can be assigned to variables and used for comparison.
9. The escape character changes the meaning of the character it precedes.
10. To evaluate the arithmetic formula `b = (-a) ** 2` where `a` is user input and
`b` is the result, you could write `a = eval(input('Enter a number for the
equation: '))`.
11. The `#!` digraph at the start of a file indicates to a UNIX or Unix-like OS how
to execute the Python script.
12. The `sys` module's `argv` can access command line arguments, as shown in
`from sys import argv; print(argv[1])`. Running `python index.py Peter 100 200
300` outputs `Peter`.
13. The `sys` module provides access to command line arguments through
`argv`.
14. Compiled Python bytecode files have a `.pyc` extension.
15. Lines 1 to 4 will be ignored for syntax checks, while line 7 contains an inline
comment.
16. `print('\\\\')` outputs `\\`, while `print('\\\\\\')` results in an error.

You might also like