Python Numbers

Types

Python Numbers

Number data types store numeric values. Number objects are created when you assign a value to them. For example -

var1 =1 var2 =10

Python supports four different numerical types -

int (signed integers)

long (long integers, they can also be represented in octal and hexadecimal)

float (floating point real values)

complex (complex numbers)

STRING OPERATION:

The+ operator works with strings, but it is not addition in the mathematical sense.Instead it performs concatenation , which means joining the strings by linking them end-to-end. For example: >>>first = 10 >>>second = 15 >>>printfirst+second 25 >>>first ='100' >>>second ='150' >>>print first + second 100150

BOOLEAN EXPRESSIONS:

Aboolean expression is an expression that is either true or false. The following examples use the operator

== , which compares two operands and produces True if they are equal and Falseotherwise: True and Falseare special values that belong to the type bool ; they are not strings: >>>type(True) >>>type(False)

x != y # x is not equal to y x > y # x is greater than y x < y # x is less than y x >= y # x is greater than or equal to y x

If the value of left operand is greater than the value of

(a > b)

right operand, then condition becomes true.

is not

true.

<

If the value of left operand is less than the value of right (a < b)

operand, then condition becomes true.

is true.

>=

If the value of left operand is greater than or equal to the (a >= b)

value of right operand, then condition becomes true.

is not

true.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download