Datatypes in Python

Datatypes in Python

Data type is a set of values, and the allowable operations on those values. Every value has a datatype. Fortunately, we aren’t forced to declare the datatype of our variables because Python is able to keeps tracks of that internally.

Built-in objects in Python

Numbers(Integer, Float, Decimal, Fraction)
Strings
Lists
Dictionaries
Tuples
Files
Sets
Booleans
Types
None
Functions
Modules
Classes
etc.

There are following native types:

integer

An immutable integer of unlimited magnitude.

4

-42

float

An immutable floating point number (system-defined precision).

1.2

1.3333

fraction

An immutable fraction number.

1/2

1/3

complex

An immutable complex number with real and imaginary parts.

3+1j

4+ 2j

string

An immutable sequence of Unicode codepoints.

‘Mirek’

“Mirek”

“””Mirek

jest z

nami.”””

tuple

Immutable, can contain mixed types.

(1,2,3,4,5)

list

Mutable list, can contain mixed types.

[1,2,3,4,5]

dictionary

A mutable associative array of key and value pairs.

{1: "Grzesiek", 'a': "Tania"}

set

Unordered mutable set, contains no duplicates.

set([‘e’, 45, 0.5, “Darek”])

frozenset

Unordered immutable frozenset, contains no duplicates.

frozenset([4.0, 'string', True])

byte

An immutable sequence of bytes.

b'Some ASCII'
b"Some ASCII"
bytes([119, 105, 107, 105])

byte array

A mutable sequence of bytes.

bytearray(b'Some ASCII')
bytearray(b"Some ASCII")
bytearray([119, 105, 107, 105])

boolean

An immutable type with two values: True or False

True

False

None

A type means non existent, not known or empty.

There are other datatypes like module, function, class, method, file, and even compiled code, but they are connected with OOP.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s