Python Tutorial : Get the length of the string in Python

Hi Friends,

As I have started learning Python, I thought why not to share the knowledge with you too?
So I first encountered the problem when I started working with strings.
I was trying to find a way to get the length of a string I am passing into a function,

So I have written a function as:

def getLengthofString(myValue):

    stringValue =  str(myValue)
    stringLength = len(stringValue)

getLengthofString("Hello, Please print the length of this string")

And here is the output which comes in my screen :

Explanation :

1.In first line we define a function with the name  getLengthofString, which accepts a parameter.
2. In second line, As python can accept anything as a parameter I am converting the passed parameter into an string by using an inbuilt function str and storing into another variable.

3. Now I am getting the length of the parameter by again using an inbuilt function len and passing the string value into this.
4. In last I am printing the length on the screen, you can see the result 45 highlighted in the screen shot.

Note: I am using PyCharm IDE to demonstrate this tutorial.

How to reverse a string through programming( In C, C#, JAVA)

If you want to reverse a string , just take a string variable and a character array and the length of the array must be same as the length of string , You can achieve this by finding the length of string. And then store the string into character array.
Now to display the string in reverse manner, Just print the array from last index to first index!!!
The example is shown here, it is in C#, you can change it into any of language by just changing the syntax.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
    class Program
        static void Main(string[] args)
            string _myString;
            Console.WriteLine("Enter any string ");
            _myString = Console.ReadLine();
            int _length = _myString.Length;
            char[] _reverse = new char[_length];
            for (int i = 0; i < _length; i++)
                _reverse[i] = _myString[i];
            for (int i = _length-1; i >= 0; i--)

Change the Admin Password of Windows-XP without knowing the password!!!

So here is the Trick with the help, You can change the password without knowing the Password.. The only condition is that you must be Log-in into Windows first. Then follow the steps...

Step 1 : Go to START MENU-->RUN

Step 2 : Just type there " control userpasswords2"

here you will get a window, You can change the password here without entering the previous one.

Now enjoy!!!

Java Tutorial : Switch case( Without break; ).

To choose one option from several available options, we can use switch statement. Dependiong on the selection option, a perticular task can be performed.


               case value1 : statements;
               case value2 : statements;
               case value3 : statements;
               case value4 : statements; 
               [default       : Default statements];

Here depending upon the value of the case perticular statement will be executed. And if there is no value match then default statement will get executed.

Example :

class switchcase
                 public static void main(String[] args)
                             char color = 'g';

                                          case 'b' : System.out.println(" Blue ");
                                          case 'r' : System.out.println(" Red ");
                                          case 'g' : System.out.println(" Green ");
                                          default : System.out.println(" No Color "); 

Here the output will be as :
No Color

because after executing first statements command will be transfered to next statements.To stop this we have to use BREAK statements aboout wich we will learn on next Tutorial... :)

Java Tutorial : For-Each Loop

This loop is specially  designed for collection elements. Collection means a group of elements. For example , we can take an array as a collection or any class in java.util package can be considered as a collection. The reason is that an array stores a group of elements like integer values or strings.


         for(val : collection)

Here , the var is attached to the collections.This var repersents each element of the collection one by one.

Example : here is a programe to see the use of for-each loop and retrieve the elements one by one from an array and display it.

//using for each loop to display array elements

class demo
           public static void main(String[] args)
                        //Declare an array with 4 elements
                        int arr[] = {210, 540,230,-23};
                       // Use of  for-each Loop
                        for(int i : arr)