• 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 15 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 10.2k points
    0 votes
    1 answer 11 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 6 days ago Code Learner 6.3k points
    0 votes
    1 answer 9 views
    Problem: Key differences between method and function in python Unlike a function, methods are called on an object. ... i.e. “my_method” on the object “cat” whereas the function “sum” 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 10.2k points
    0 votes
    1 answer 21 views
    Problem: I wrote the following code which extracts the info. of a file and orders it alphabetically based on its second column objects: import csv import operator import sys def re_sort(in_file='books.csv', out_file='books_sort.csv'): data = csv.reader(open('books. ... function. Do you guys see reasons why this may be happening. The following if a structured version of the contents in the file
    asked Feb 21 Mashhoodch 10.2k points
    1 vote
    1 answer 75 views
    Problem: I have recently started learning C language. Let’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 7 views
    Problem: I have a class to create an object that forms a polynomial of any degree. And the class with its private part would be like this according to the example I'm trying to try to understand: class polynomial { public: // ... private: double * ... pointer within a class as in the case of double *coeficiente;Where is the dynamic vector created? That I do not understand. Thanks again.
    asked Jan 24 sasha 13.2k points
    0 votes
    1 answer 4 views
    Problem: self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python. It binds the attributes with the given arguments. What the reasons i need to use self?
    asked Jan 23 Mashhoodch 10.2k points
    0 votes
    1 answer 38 views
    What is the naming convention used for the Python wheels at http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy For example, for scipy here are two of names of wheels on the page: scipy-0.17.0-cp27-none-win32.whl scipy-0.17.0-cp27-none-win_amd64.whl What does 'none' ... and win_amd64? Does it matter if I'm using the x86 or x86-64 version of Python (ref www.python.org/downloads/release/python-2711/)?
    asked Oct 27, 2020 psandprop 2.4k points
    1 vote
    1 answer 26 views
    Problem: Can anyone guide me with the right solution as I am new and learning programming? Write the code to call the function named send_signal. there are no parameters for this function?
    asked Feb 18, 2020 maddi86 5.4k points
    0 votes
    1 answer 2 views
    Problem: How to I Solve this: attributeerror: 'function' object has no attribute HELP! I need help understanding this: attributeerror: 'function' object has no attribute Can someone please help solve this, I am new in python().
    asked 1 day ago Mashhoodch 10.2k points