DEV Community

Volkan Ozdamar
Volkan Ozdamar

Posted on

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 standardized 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

>>> 3
3
>>> 0b10110
22
>>> -47
-47
>>> 0o5
5
>>> 0o12
10
>>> 0x21
33

-Floats

Float numbers wider than integers and the are fractional numbers.They have got negative and positive values and decimal point.

>>> 3.0
3.0
>>> -24.3
-24.3
>>> 8e-2
0.08

e is using for scientific notation and retuns a float value multiplied by the specified power of 10.

-Complex numbers
Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part.

-Strings

Strings are character sets.We create strings enclose charactes with single quotes or double quotes.

>>> "Hello , World!"
'Hello , World!'
>>> 'This is a sentence'
'This is a sentence'
>>> "I'm a developer"
"I'm a developer"
>>> 'I\'m a developer'
"I'm a developer"

If we need to use single quote , you have to enclose characters with double quote and vice-versa.Either , you can use escape character backslash "\".

-Boolean

Boolean has two value.True or False.We can test boolean values simple binary logic problems.

>>> True and False
False
>>> True or False
True

Top comments (0)