top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Python: What all rules are defined for variables in python ?

+3 votes

Sometimes python shell throws error while declaring variables . Is there any single place where all the rules are defined ?

posted Apr 23, 2016 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

A variable is a memory location where a programmer can store a value. The value stored in a variable can be accessed or updated later. The interpreter allocates memory on the basis of data type of a variable.

Variables names must start with a letter or an underscore, such as:


The remainder of your variable name may consist of letters, numbers and underscores.


Names are case sensitive.

case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable.

Good Variable Name

Choose meaningful name instead of short name. roll_no is better than rn.
Maintain the length of a variable name. Roll_no_of_a-student is too long?
Be consistent; roll_no or or RollNo
Begin a variable name with underscore(_) character for special case.

answer Apr 27, 2016 by Manikandan J
Similar Questions
0 votes

I want to submit a qsub job to my hpc cluster from within python. In this case, I must set some environment variables specific for this qsub job and then invoking a bash script from within python.

What python code should be used for this job?

+2 votes

I want to take the file, "desktop/test.txt" and write it to "desktop/newfolder/test.txt". I tried the below script, and it gave me: "IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'". Any suggestions would be great.

def firstdev(file):
 in_file = open("desktop/%s.txt") % file
 indata =
 out_file = open("desktop/newfolder/%s.txt", 'w') % file

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.