Table of Contents

## Comments,Indentation,Built-in Number Data types and Expressions in Python

### 1. Comments in Python

Comments are statements given by programmer for better understanding of programs.They are non executable statements.

Comments are of **two** types:

#### Single line comments

Single line comments are given by using **‘#’** symbol before writing statement.

**EXAMPLE**

#code to display itvoyagers print('itvoyagers')

#### Multi line comments

Multi line comments are given by using opening and closing **“”” “”” or ”’ ”’** symbol(triple quotes) before and after writing statements.

**EXAMPLE**

"""code to display itvoyagers and to show example of multiline comments""" print('itvoyagers')

### Indentation in Python

Other programming languages uses opening and closing braces {} to define a block of statement.

This braces are replaced in python with indentation.

Indentation is important both IDLE and Script mode.

Indentation can be given as four spaces or one tab key.

**EXAMPLE**

for i in range(5): print('itvoyagers') else: print("sorry range exceeded")

**Note: in above example if indentation is not given then it may lead to indentation error**

### Built-in Number Datatypes in Python

Various classes like integer,floating point,long and complex indicates numeric values.

These can be defined as int, float, long and complex.

#### a. Integer (class int)

Integers can be positive or negative and are of unlimited size in Python.

**EXAMPLE**

143,-426

>>> 82-951+6 -863 >>> 1500087521651235122453210452104520+9 1500087521651235122453210452104529 >>> 2**945 297403381695556612559612499629980112026252040331878891811154371863188131432080874709033662899231270117959744758038594610090917049108981141558166116220478925156594168089491974788537281966859547374047839156470287441213549741375576017631419788069731616602409021090828782564753069762936832 >>> len(str(2**945)) 285

**Note: Above examples shows that integers are of unlimited size in python **

#### b. Floating Point Numbers(class float)

Floating point numbers can be positive or negative which comes with decimal point and an optional exponent (e or E)

Floats are 64-bit double precision floating point numbers.

**EXAMPLE**

10.2,-9.6,3e4,-3E-4

>>> 5.42*-4e5 -2168000.0 >>> import random >>> random.random() 0.5292462067367842 >>> 2.0**945 2.974033816955566e+284

#### c. Booleans (class bool)

Boolean values like True and False is given.

Here T and F are capitalized in boolean values.

In Python 0,None and empty value such as empty string “”,”,empty list [],empty dictionary {},empty tuple() etc are considered as **False** and anything apart from this is considered as **True**.

**EXAMPLE**

>>> True + 5 6 >>> False + 10 10 >>> True-False 1 >>> 50==50 True >>> 50==80 False

#### d. Complex Numbers(class complex)

Complex numbers have two parts i.e. real and imaginary.

Real can be any integer and imaginary part is having ‘j’ as suffix

eg.(3+2j)

**EXAMPLE**

>>> 3+2j *8 (3+16j) >>> 3+2j+5 (8+2j) >>> 3+2j-2 (1+2j) >>> k=9+5j >>> k.real #to get real number 9.0 >>> k.imag #to get imaginary number 5.0

### Expressions in Python

An expression is a combination of values,variables and operands.

**EXAMPLE**

>>> p=120 >>> p+60 180 >>> 12 12 >>> 8+(2-1)*9 17 >>>

For other python basics related posts:

For other advanced python related posts: