• Register

 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.


Legal Variables:

myvar = "John"

my_var = "John"

_my_var = "John"

myVar = "John"

MYVAR = "John"

myvar2 = "John"

Illegal variables:

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.

def my_function(fname):

  print(fname + " Refsnes")





The output of the above program is;

Emil Refsnes

Tobias Refsnes

Linus Refsnes
posted Jul 3 in php 160 points