Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

Coming from a C# background the naming convention for variables and method names are usually either Camel Case or Pascal Case:

// C# example

string thisIsMyVariable = "a" 

public void ThisIsMyMethod()

In Python, I have seen the above but I have also seen underscores being used:

# Python example 

this_is_my_variable = 'a' 

def this_is_my_function():

Is there a more preferable, definitive coding style for Python?

1 Answer

0 votes
by (106k points)
edited by

Following are some important Python naming conventions:-

  1.  Package name:-Package name will always be written in Python in lower 

E.g:-  import pandas as pd

  1. Variables:-Python does not have any special variable naming convention because we need not specify variable names like other languages.

  2.  ClassName:- While writing class name we will write the first letter as capital.

E.g:- class Summation(object):

  1.  Function name: -It should be lowercase, if your function name contains more than one word then it must be separated by underscores as necessary to improve readability.

E.g:- def plus_minus(a,b):

If you are looking for upskilling yourself in python you can join our Python Training and learn from the industry expert!

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 20, 2019 in Python by Sammy (47.6k points)
0 votes
2 answers
asked Jul 13, 2019 in Python by Sammy (47.6k points)

Browse Categories