Here you go!!..
Learning new programming languages is quite equal to learning new regional language. I have head started with python programming language which is one of the oldest programming languages . It is has OOPS concept so that if we are familiar with OOPS concept then this programming language should be quite easy for us to learn. Only syntax varies.
To start with i have tried to write a smallest program in python language.The problem statement is very simple
Write a program to find 2 consecutive vowels in a string .Consider those two consecutive vowels as one character and return the number of characters in that string.
I have used an online editor http://www.tutorialspoint.com/execute_python_online.php to learn coding practically.Now let me show you step by step to execute this small program
3.Rename newly created file with appropriate file name.
4.Inside the new class file write the functionality
In the above mentioned code
In the above statements
Learning new programming languages is quite equal to learning new regional language. I have head started with python programming language which is one of the oldest programming languages . It is has OOPS concept so that if we are familiar with OOPS concept then this programming language should be quite easy for us to learn. Only syntax varies.
To start with i have tried to write a smallest program in python language.The problem statement is very simple
Write a program to find 2 consecutive vowels in a string .Consider those two consecutive vowels as one character and return the number of characters in that string.
I have used an online editor http://www.tutorialspoint.com/execute_python_online.php to learn coding practically.Now let me show you step by step to execute this small program
- When you open the Online EDITOR linkby default you can see root folder and under that root folder there is file named main.py
2.Now right click on Root folder and select Create new file. This is new class file in which we are going to write functionality. Infact you can write functionality withn the main.py file also. PY is the extension of python class file.
3.Rename newly created file with appropriate file name.
In the above mentioned code
- removeVowels is the class name .If there is a statement of line which is based on one of teh condition or which belongs to some code block then the parent statement should be end COLON(:). Since all of the functionality will be inside the class name , so we add colon at the end of the class.Here class is a keyword to represent its immediate next word is class name
class removeVowels:
- getLength is the method name. You can see that at the end of the method there is a COLON. it means inside the method some lines of code are there which are strictly inside that method code block. the keyword def represents the word which is present immediately next to the def is METHOD/function.
def getLength(randomVariable,word):
NOTE: in python INDENTATION plays biggest role. Huh!!!.. indentation means TAB. If a second line of the code is depending on the first line then after writing first line of the code and adding COLON at the end of that line you need to press ENTER key. Now you need to press TAB key. in the above two statements under bullets point THE CLASS AND METHOD are inter linked. Hence after writing a line of words for class and adding colon at the end, now press enter key and press TAB key. Write statement for METHOD getLength. You can clearly spot this in the 4th image
- Now you can see another two lines of statement in which there is no colon and no TAB (indentation)
vowel='aioue'for loop is not having a tab after the statement vowel='aioue'. Because these two lines of the code are independent .Now whatever we are going to write inside for loop should be indented.Means TAB
for i in range(len(word)-1):
- For loop ends with colon .If condition is inside the for loop and again if condition has some statement. So ideally if condition should have colon at the end and its statement should have one tab space after the if condition
5.Now double click on main.py file so that it gets opened . From this file we need to create instance of that class in the newly created class file.
In the above statements
- So the functionality is in some other class and some other file.Not in main.py . So logically we need to import that class and its class file to our main.py from which we call the functionality inside that class.Inorder to do so, we need import the class and class file to calling class(main.py). The syntax is
from RemoveVowel import removeVowels
In the above line of code from is a keyword . RemoveVowel word which is present immediately after this from keyword is CLASSFILE name without .py extension. in our case the new file name in which our class and method are present is RemoveVowel.py . So use only the file name here. Now import is also key which and the word which is present immediately after the import keyword is the class name. In our case the class name is removeVowels. You can see the code
- Create object of the class as per below. In order to access any method,properties,variables inside any CLASS from another class , we need to create the object of that class. The statement is as mentioned below.
cls is object of the class removeVowels.open and closed brackets represents you care invoking constructors of the class. This is how we invoke class in any object oriented programming languages
cls=removeVowels();
- Now you have got object of the class. By using the object of the class you class the method as follow
cls.getLength("wuut")
6. Now execute the code by clicking on execute button in the editor
you can see the output in the output window which is present at the bottom of the editor. You can use the code here CODE
Happy coding!!!.. I will share some more tips and tricks from other programming languages such as server side, client side and database
Comments