It is true that the python function names follow the same rules for naming variables.
Rules for python variables:
The rules for declaring the python variables are;
- A variable can have a short name like x and y or more descriptive names like age, total_volume.
- A variable must start with a letter or underscore.
- A variable can only contain alpha-numeric characters and underscores.
- Variable names are case sensitive like age, Age, and AGE is different.
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
2myvar = "John"
my-var = "John"
my var = "John"
The illegal variables will display the following output;
File “demo_variable_names.py”, line 10
2myvar = “Jhon”
SyntaxError: invalid syntax
Example of Python Function:
Variables can be passed into functions as an argument. Arguments are specified after the function name inside the parentheses. The user can add as many arguments as he wants.
The following example has a function with one argument.
print(fname + " Refsnes")
The output of the above program is;