Saturday, 3 February 2018

This was all theory of basic data types in python.
Now, let's get our hands dirty.

We have our python softwares downloaded.
Search for python and openn the python software.
The opened black window is called as python interpreter.
There you can experiment things which you dont want to save.
We'll be working in the python interpreter for learning about new modules and properties. But for writing big programs, we'll be using "IDLE" which is downloaded by default when you download python software.

Pressing Enter in python interpreter will execute the typed command.
i)int :
     type any number and press enter:
         >>> 21
         21
     This is what you get.
     Now, how to know what data Type is it.
     You can do this using type()
     For example :
         >>> type(34)
         <class 'int'>
     Python interpreter can be used as a calculator.
     
        >>> 12 + 32 -468
        -424

        >>> 12*234
        2808
        >>> 85456/98
        872.0
     Note : what result you get after division is a float type.

     ** : This is a operator used to find exponent of syntax : a**b
           This will find a raised to b or a * a * a*... *b times.

        >>> 27**3
        19683

     % is mod operator.
     it requires two operands:
     % finds remainder. a%b will return the remainder when a is divided by b.

        >>> 56%47
        9
     
     We'll now learn about type casting using python3.
     int(x) is the syntax to be used.
     
     For Example:
        >>> int(63)
        63
        >>> int(34.32)
        34
        >>> int("1265")
        1265

No comments:

Post a Comment

Memoization : Memoization is a technique for remembering the results that incur huge costs to running time to the algorithm. Memoizati...