Talk like Pythonista 1 - Data Types


Talk like Pythonista 1 - Data Types

In programming languages data types using to represent and understand the value of data.Beside of that , we can decide what operations can be performed on data.Each programming languages has same approaches generally , but it is not standartized and every languages has their data type classification.

In Python , we’ve got

-Numbers
-Boolean
-Strings

NUMBERS

Any numeric value classified as Number.These numbers has types according to their represented data.These are integers , floats and complex numbers.In Python 3 , the limit is only computer memory for decide to how long data will be represent.However float values are represented as 64-bit double-precisions.

-Integers

Positive or negative whole numbers are integers.Python using decimal system for all numbers.However if we need to other number systems,we can use prefix with numbers.

Prefix Interpretation Base
0b (zero + lowercase letter ‘b’) Binary 2
0o (zero + lowercase letter ‘o’) Octal 8
0x (zero + lowercase letter ‘x’) Hexadecimal 16

Some examples with integers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> 3
3
>>> type(999002)
<class 'int'>
>>> 0b10110
22
>>> 0o5
5
>>> 0o12
10
>>> 0x21
33
>>> type(0x0124)
<class 'int'>

type() method returns class type of the argument(object) passed as parameter.

-Floats

Float number are fractional.

1
2
3
4
5
6
7
8
>>> 3.2
3.2
>>> -45.6
-45.6
>>> type(412.0004)
<class 'float'>
>>> 1e6
1000000.0

E-notation is known as exponential notation or scientific notation.1e6 is equivalent to 1×10⁶.