Skip to main content

First program in Python!!!

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

  1. 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.

4.Inside the new class file write the functionality














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 i in range(len(word)-1):
 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 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

Popular posts from this blog

error occurred in deployment step 'recycle iis application pool' :object reference not set to an instance of an object

While deploying using Visual studio, we may get an error "error occurred in deployment step 'recycle iis application pool' :object reference not set to an instance of an object" Solution:  Don't get  panic ..Simply restart the visual studio with the solution which you wanted to deploy on to the site This may help some one. -cheers pradeepa achar

The Fastest way to Export Schema of Sharepoint List

Many of my SharePoint Developer friends are struggling to get the Schema.xml file of a newly created list. The schema.xml file has the list's metadata information, by using the schema.xml, we can create the lis definition and paste this contents of Schema.xml to the Schema.xml file of the newly created List definition, so that you can deploy the list definition on another site. In order to do this, you guys might be following the procedure bu saving the site template and get the site definition solution. After this, you will open visual studio and import this solution and wait for few minutes. THIS IS A CRAPPY PROCEDURE..Why do you invest your time to get a schema of one or few list  by taking entire site definition?..If that site has lots of lists, then it will take lots of time. In my Research, i have found a the BEST  and quicker way to get schema.xml file of a particular list which you need Schema.xml. Follow the following procedure : Go to your site  click ...

The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator

You might have developed a functionality where data is being saved in a SharePoint list. By the time you developed this functionality it was working fine.As users adds the data , some day your functionality doesn't work. That means, the data which is present in the list is not being retrieved. Don't be panic. Just open the LOG file which is present in 14 hive folder. You will come to know about this bug with the statement -"The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator". Now what you have to do is, go to central administration site.  1.Click on Manage web application 2.Select the web application on which your sitecollection is created. 3.Click on General settings and select Resource throttling 4.by default list view threshold would be 5000. your list might have data more than 5000. So , increase the number to required threshold limit. you can make it 10000, 20000 like this. Do a i...