Jan 17, 2015

Textual description of firstImageUrl

Python fundamentals - Data types and In-built Objects

In previous section we installed python and run hello world program. Now we will delve into building block of python language and will write sample program to understand the same.
As we know that python is both procedural and object oriented language. We will focus on Object oriented aspect of python.
Python is an object-oriented language and classes form the basis for all data types. Python has various built-In Classes like int for integers , float for floating point values and str for character string. i,e: Every thing in Python is class, even primitive data type.
Consider following statement in python :
    student_cgp  =  7.65
How do we interpret this in python - student_cgp is an identifier and it references a floating point object with value 7.65. Two important point need to be noted here is :
1. Identifiers in python are case-sensitive.In Python, identifier is similar to a reference variable in Java or a pointer variable in C++. Each identifier is implicitly associated with the memory address of the object to which it refers.
2. Unlike Java and C++, python is a dynamically typed language, there is no advance declaration associating an identifier with a particular data type. Although an identifier has no declared type, the object to which it refers has a definite type.
Below is the list of built in class in python. It can be classified broadly mutable and immutable classes. Object of immutable classes cannot be changed subsequently once it has been instantiated.
Commonly used built-in classes for Python
Note : 
1. Bool class instances are expressed as the literals True and False.
2. Numbers are mainly of two types - integers and floats. In Python, int and float classes are the primary numeric types. Default value from constructor int() is 0 and float() is 0.0.
3. In Java and c++, we have different int type based on precision. However,python automatically chooses the internal representation for an integer based upon the magnitude of its value.

Before moving ahead we will execute some code in python interpreter and predict outcome:
    >>> int(3.14)
    >>> int(-3.99)
    >>> int('137')

Operators in python:- 

Almost all operators are present in Python as in other languages, some of them needs special mention are as follows :

Comments in python:-

In python single line comment is done using # (pound).Below code uses # for comment: 
 # I am comment- it will print Hello World
  >>>print 'hello world'
  hello world
Note:  It is recommended not to use triple-quotes for block comments as it is for documentation strings not block comments, although it has a similar effect.Always use # in for single or multiple statements. 

Previous : Introduction and installation                                 Next: Python Control Flow (If-Else, While, For Loop)
Location: Hyderabad, Telangana, India