• Register
1 vote


I am new in programing and and I am confused about python function names follow the same rules for naming variables. 

Can anyone explain?

10 7 2
6,060 points

Please log in or register to answer this question.

2 Answers

1 vote
Best answer


The rules are:
1. Python function names follow the same rules as they are for naming variables. 
2. The functions header marks the beginning of the function definition. 
3. A function definition specifies what a function does and causes the function to execute. 
4. A local variable can be accessed from anywhere anytime in the program.

Hope you understand this In python function name follow the same rule as naming variable rules but it does not cause the function to execute and it might be accessable from anywhere anytime .

For more information you can visit:



11 6 4
34,950 points
0 votes


Variable Naming Conventions and Rules

You may be noted with algebraic equations, such as the quadratic:

ax² + bx + c = 0

In mathematics, variables are usually single letters like x, y, and z, or Greek symbols like π or θ. Mathematicians mostly exercise variables at the time they don’t know a particular value however are performing towards tracing it. It’s diverse in Python. You should assign a value to a variable before you can employ it, in fact in case that value is zero or empty. For example, I call the variable Guido prior assigning it a value:

>>> Guido

I will get the following error:

Traceback (most recent call last):
 File "", line 1, in 
NameError: name 'Guido' is not defined

Variable assignment performs left to right.

>>> Guido = 0

Is acceptable. As is:

>>> Guido = ""

And even:

>>> Guido = False

However the following will give you a this error.

>>> 0 = Guido
>>> ‘’ = Guido
>>> False = Guido

The first two gave you an error that peruse:

 File "", line 1
SyntaxError: can't assign to literal

However the last one gave you an error that read:

File "", line 1
SyntaxError: assignment to keyword

That’s cause False is a reserved word in Python. It’s what computer scientists note to as a Boolean value, and you can’t exercise it as a variable identifier. There’s a Python module named keyword. It has a function named kwlist. Importing keyword and calling kwlist will return a list of Python’s keywords. Attempt it:

>>> import keyword
>>> keyword.kwlist

Those are all the words you can’t exercise. However that’s okay. At the times it comes to variable names, the sky is the limit! Well, almost. There are few rules you require to follow and few conventions you ought.

The Rules

1. Variables names should begin with a letter or an underscore, such as:

  • _underscore
  • underscore_

2. The residual of your variable name may compose of letters, numbers and underscores.

    • password1

    • n00b

    • un_der_scores

  • Names are case sensitive.

    • case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a diverse variable.

The Conventions

  • Readability is very significant. Which of the following is simpliest to read? I’m expectant you’ll tell the first example.

    • python_puppet

    • pythonpuppet

    • pythonPuppet

  • Narrative names are very helpful. In case you are writing a program that includes up all of the bad puns made in this book, which do you think is the better variable name?

    • total_bad_puns

    • super_bad

  • Avoid employing the lowercase letter ‘l’, uppercase ‘O’, and uppercase ‘I’. Why? reason the l and the I look a lot like each other and the number 1. And O looks a lot like 0.

    10 6 4
    31,120 points

    Related questions

    0 votes
    1 answer 2 views
    Problem: Any solution to this iisue > Python function names follow the same rules as those for naming variables.
    asked 5 days ago ummeshani 9k points
    0 votes
    2 answers 2 views
    Problem: None of these commands will retrieve the docstring of a function and assign it to a variable. How can it be achieved? I attempted various things. One of which is the help function, but it seems to activate an entire program as opposed to returning a string. I ... : python << EOF import inspect import PIL doc = inspect.getdoc(PIL) print doc print type(doc) EOF So it has no documentation .
    asked 3 days ago ochena 22.1k points
    0 votes
    1 answer 38 views
    Problem: What do we use the second parameter of the open() call to indicate?Whether we want to read data from the file or write data to the fileWhat Python function would you use if you wanted to prompt the user for a file name to open?What is the purpose of the newline character in text files?
    asked Jan 23 Mashhoodch 13k points
    0 votes
    1 answer 4 views
    Problem: how to I Solve this: error: what does the return function do in python HELP! I need help understanding this: what does the return function do in python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
    asked Mar 11 Mashhoodch 13k points
    0 votes
    1 answer 67 views
    Problem: I want to know the correct answer to the following multiple-choice question: Which python keyword indicates the start of a function definition? rad help break def I am a beginner so I have not reached the advanced topics. So I want the explanation for the rest of the words in addition to the correct one. Thanks!
    asked Mar 5 Code Learner 9.8k points
    0 votes
    1 answer 91 views
    Problem: Hi! I am a beginner and got stuck on an assignment in which I am asked to write a python function that takes three arguments and after performing some calculation, should tell whether the three values can be used to create a triangle. I am unable to build the logic. Please help!
    asked Feb 25 Code Learner 9.8k points
    0 votes
    1 answer 12 views
    Problem: Key differences between method and function in python Unlike a function, methods are called on an object. ... i.e. &ldquo;my_method&rdquo; on the object &ldquo;cat&rdquo; whereas the function &ldquo;sum&rdquo; is called without any object. Also, because the method is called on an object, it can access that data within it. Discuss the difference in detail
    asked Jan 22 Mashhoodch 13k points
    1 vote
    1 answer 141 views
    Problem: I have recently started learning C language. Let&rsquo;s say I have a myprog.c file in which I have the local variable a. Now I want to know can I also have the function in my above c file which has the very same name a? As far as I know a local ... if I tried this my compiler greets me with the error. I want to know if this is the compiler specific error or it is actually the error.
    asked May 25, 2020 Martin K 6.6k points
    0 votes
    1 answer 15 views
    Problem: Hello! I have the following program: def add(number1, number2) : return number1 + number2 def subtract (number1, number2) : return number1 - number2 def product (number1, number2) : return number1 * number2 def divide (number1, number2) : return number1 ... have picked the code for functions from the Internet and I have just added the functions calls. Please help in resolving the issue.
    asked Apr 19 Code Learner 9.8k points
    0 votes
    1 answer 5 views
    Problem: What should be the possible answer of how to call another function in python?
    asked Apr 17 ashik 14.6k points