0:00
Hey guys, welcome back to this video
0:07
In this one, I'm going to give you a five steps method that will help you with the syntax
0:13
of Python. So if you're new to Python and you often get confused with it, with its syntax and you don't
0:20
know how to work in Python, so this video is for you
0:25
Without further ado, let's get going. So the first thing I want to talk about is understanding the syntax of a function
0:35
Well, that's just easy. Whenever you see some words, whenever you come across with words, that are directly followed
0:43
by parentheses, whether it be empty parentheses or those parentheses inside of it, there's some data
0:51
It doesn't matter. But that's the simplest way to know what's a function and what should not be considered
0:58
as a function. So let me give you an example. I have a function print. So now this is a function, right
1:04
This is the function name and is directly followed by parentheses. So this is now a function. And remember one another point that functions are independent, which means that they do not require to work on some specific type of data. Like print as a function, it works independently. I have another function which is called int. So it's also a function
1:28
function which doesn't require to work on some kind of specific object
1:35
We have another function which is called STR. So these are all our functions and they work independently
1:42
We use functions to perform a specific task. So this can help you to understand or to figure out what are functions and what are not functions in Python
1:55
So I hope this is clear. Let's talk about the second one
2:00
Methods are somewhat similar to functions but they work dependently. Means that a method usually works on a specific type of object Like there might be methods which only work with strings and there will be methods that work only with lists or with twoples and so on So it has dependency So let me give you an example I have a list suppose a equals to 1 2 3 and 3 So I want to count the digit 3 that appears in this list So how would I do that I simply type print
2:41
A dot count and then I'll pass whatever I want to count so three so it will print out two because there appears
2:51
two times the digit three so you know you see the difference between the function syntax and a method
2:58
syntax see a method first of all we type the object name and then a door operator
3:05
followed by the function name and its parentheses method name sorry and parentheses
3:11
So this is the syntax of a method and there's another one suppose I have a string
3:18
s equals to hello I just want to check out that is this string in lower case
3:26
So how would I do that as that low is lower is lower and then I'll leave the parentheses empty
3:35
So these both are methods now you see I cannot use is lower with a list or a tuple because
3:41
because this is a method that only works with strings and Kant works with a tuple and list as well
3:50
So this is the difference between a list and a function. Functions work independently while methods are dependent
4:01
I hope this is clear. Let's talk about the third point. So the third point I want to give you is understanding the syntax of statements
4:10
you know we have a couple of statements in python so suppose we have a statement if so if a equals to suppose b
4:19
you need to learn that you need to understand that a statement always and always ends with a colon symbol
4:27
so whenever you come across colon symbols and it uh it begins with a specific keyword just know that a statement right And then you you know you see that there is some eye indentation right
4:42
And this is, I mean, then you might see that there is a block, a specific block
4:48
So you need to learn what are statements in Python, how they are written
4:54
So the fourth step is distinguishing between a variable and a string
5:01
I see a couple of beginners, what they do is that they get confused with a simple string and variables names
5:10
So suppose I have a variable name hello equals to 10. So now this is a variable and I have another variable that's holding a string hello
5:20
So sometimes they get confused when they're saying, When they want to work with strings, they don't enclose it in double cuts
5:29
And when they want to work with variables, then they enclose it in double codes
5:35
So sometimes, yeah, they get confused. So if I print out hello here by not enclosing it in double cuts
5:44
So what it will print out, it would definitely display 10 because a hello is a variable
5:50
Keep in mind that a variable's name is never enclosed in. double quotes and when that's being enclosed in double quotes it would be considered as a string
5:59
I hope this is clear so if I enclose it in double cuts it will print out hello
6:05
but if I remove these double cuts it would definitely print out then because that
6:13
would be considered it's a variable name so just know that strings are always
6:18
enclosed in double quotes while variables are never enclosed in anything. You just need to type it and assign value to it. Well that's it. Let's talk about the most
6:31
important and the last step. Well, what is that? Is understanding indentation. So what is
6:38
indentation Well indentation basically defines a block of code in Python See this is determined right here Now this is considered as a separate block Why Because because of the indentation These empty spaces white spaces
7:03
are considered as indentation. So if I want to insert some more statements into
7:11
this block, suppose another statement print, then another one, whatever B, That's done. If you want to go out of this block and you want to start another block of code
7:22
another statement you want to work with another statement or you want to apply a function or whatever you want to do but not inside of this block
7:32
So you'll simply have to start another line from the beginning. I mean right from here you don't have to leave any empty spaces when you want to start another block
7:45
If you simply want to add a block of cord, just simply don't leave any white spaces before starting another block
7:56
That's how it's considered. Suppose it's another block here. Suppose it's another one here, another statement, suppose a function definition, if A, add, whatever B
8:09
So if I insert statements here. Now these are two blocks. This is the first block, this is the second block of cord, and it's how
8:22
Python knows that this is another block because of the indentation. So if I won't leave indentation here like if I put like this
8:31
Then this all the entire these all lines would be considered as a one block. So we need to know how to work with indentation in how to define different
8:44
blocks of code in Python. I hope this is clear. Well, that was all for now. I hope this video
8:50
has helped you in one way or other. If it did help you, give it a thumbs up. Subscribe
8:58
me for more programming videos and thank you for watching. See you in another one