Hello and welcome to this lecture and this lecture we will discuss about how to name a certain things
while writing Python code.
So I actually mentioned or I actually explained you guys the importance of writing clean Python code
but there is one trick I would like to give you guys which is eventually going to help you when you
appeal for your interviews.
So in a lot of interviews what happens is that when programmers actually assign a certain task to do
or certain code to write.
Obviously when you're writing it on a white board it does not matter.
But when you're actually asked to code on a machine or what some interview was actually DO is that they
actually look at how efficient your code is that is how logically efficient your code is as well as
some of them actually pay attention to how systematically or how cleanly you write that particular code.
Now this does not happen in all of those interviews but if you actually work on writing clean code that
is eventually going to set you apart from other candidates which are going to appeal then you obviously
you need to learn other things as well.
But this is actually going to be an added advantage or an added skill which could make a difference
so please make sure that you don't ignore the section just because it does not matter.
This is actually one of the most crucial sections.
If you actually want to become a professional programmer.
OK so I guess that's enough for the tips.
And now let's move on to the cool content of this letter that is naming conventions.
So the first rule for naming convention is that classes should always be named in a camel case format.
So it gives format as nothing but let's say if you have to write something like let's say a new number.
So instead of typing this new under school number in camel case what you do is that you type something
very in you have the first letter of your word in capitals So you type in capital you type new and then
for the next word you again start capitalizing the first letter so you type number.
So this is one of the most efficient ways to name a particular class because this actually makes it
easier for any programmer or any person who is maintaining your code easier.
Because if you write something like let's see new number as you could see it's really really difficult
for anyone to read this and figure out what this actually means.
And if you would notice the camel case actually looks much better and also it's much more readable as
compared to the other two formats.
So while declaring any class you always make it a point to define it using a camel case.
Let's take an example.
So let's say you want to define a class which is new students so you could type in class new students.
So this is one way of doing so.
But if you could notice this thing is not Lucchese and it does not look readable at all.
And if you follow it it is going to say class name should use camel case convention.
So a better way of writing the same code is by typing class new students.
And as you could see the camel case looks much more appropriate and much more readable.
So this was Rule number one about naming conventions and the next rule is that functions and variables
should always be in lowercase.
So this was all about classes.
Now let's see if you have to define a function.
So defining a function.
Let's see if you have a function which you want to name calculate to 2.
So instead of defining that thing as let's see calculate 2.
So this actually is syntactically correct but in so doing so what you do is that you define function
names in small letters so you could type and calculate total.
So what this actually does is that if you actually define functions in this type of syntax program actually
understands that this thing is a function.
On the other hand if you specify something in camel case that means a programmer immediately realizes
that this thing is actually a class.
So I like the functions always make it a point to write it in lower case letters.
And also let's say if you have to pass certain variable here you always type it in lowercase as well.
So instead of passing in number 0 here like this as you could see if you will it it says argument Neame
should be Lokis.
Let's type in number in lowercase.
And as you could see we have no problem.
So even if you have to define a particular variable inside your function.
Always make it a point to type it in lowercase.
So as you could see you could define a result equal number of way here.
So this actually is going to make your code much more readable and understandable by your coworkers.
So now the next thing the next rule is that the instance method should always use self as the name of
force parameters.
So let's say you are defining a class.
So if you type in class let's see student and you define a certain method or.
So let's say that you type in method name as display name.
So what you do is that you type in let's see display and the school name.
And as soon as you type the first parentheses as you could see self is immediately included as the first
parameter.
And this is the by default keys and you have to pause the first barometer or for the instance method
as self because that's what the convention actually states.
So you have to keep these three things in mind while you actually name your functions your classes and
your variables.
So thank you very much for watching and I'll see you guys next time.
Thank you.