Attend FREE Webinar on Digital Marketing for Career & Business Growth Register Now
Fulfill Your Career Objectives

Take Our Free Counselling Session

• This field is for validation purposes and should be left unchanged.

# Introducing Python Data Types

/

In the Programming context, a Data Type may be defined as a classification that specifies which type of value a variable has, and what type of mathematical, relational, or logical operations can be applied to it without causing an error. Python Data Types are mainly of 3 types: Boolean, integer, and string. These may also be called the core data types in Python.

The goal of the discussion is to introduce some key ideas such as:

• Core data types in Python:
• Long data types in Python
• Standard data types in Python
• Mutual data types in Python

Let us take a quick look at Python’s core data types.  They are known as core data types because they are effectively built into the Python language—this implies that there is a specific syntax for generating most of them.

Python’s Core Data Types include:

• Numbers
• Strings
• Lists
• Dictionaries
• Tuples
• Files
• Other types include: Sets, types, None, Booleans

Date: 30th May, 2020 (Saturday)
Time: 10:30 AM - 11:30 AM (IST/GMT +5:30)
• This field is for validation purposes and should be left unchanged.

Some of these are also called Standard data types in Python.

1. ### Numbers:

Among Python Data Types, numbers are the most important. The usual object sets may include integers (numbers without a fractional part), floating-point numbers (roughly, numbers with a decimal point in them), and other types (like unlimited-precision “long” integers, complex numbers with imaginary parts, fixed-precision decimals, and sets).

Python’s basic number types support the normal mathematical operations. For instance, the plus sign (+) performs addition, a star (*) is used for multiplication, and two stars (**) are used for exponentiation:

Other data types in Python include more exotic number objects—such as complex numbers, fixed-precision decimal numbers, and sets—and the third-party open-source extension domain has even more (e.g., matrixes and vectors).

Long Data Types in Python/Long Integer Data Types:

Long integers, also known as long or long integer data types in Python, are integers of unlimited size, written like integers and followed by an uppercase or lowercase L. These long data types in Python exist only in Python 2.x.

Integers that are too long to be stored in a 32-bit integer is automatically made into Longs. However, you can explicitly create one by adding an L after the number

Complex Numbers:

Complex data types, also known as complex numbers are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b. Complex numbers are much in use in Python programming.

### 2. Strings:

Strings, one of the core data types in Python are used to record textual information as well as arbitrary collections of bytes. Strings are also an example of what we call a sequence in Python—that is, a positionally ordered collection of other objects. Sequences in Python, maintain a left-to-right order among the items they contain: their items are stored and fetched by their relative position. Precisely speaking, strings are sequences of one-character strings; other types of sequences include lists and tuples.

Sequence Operations:

Strings, quite like sequences, support operations that assume a positional ordering among items. For example, if we have a four-character string, we can verify its length with the built-in length function and fetch its components with indexing expressions:

Every string operation is, actually a sequence operation—that is, these operations will work on other sequences in Python as well, including lists and tuples. In addition to generic sequence operations, though, strings have operations all their own, available as methods (functions attached to the object, which are triggered with a call expression).

Python allows strings to be enclosed in single or double quote characters and it also has a multiline string literal form enclosed in triple quotes (single or double). When this form is used, all the lines are concatenated together, and end-of-line characters are added where line breaks appear.

Python also supports a “raw” string literal that turns off the backslash escape mechanism (they start with the letter r), as well as a Unicode string form that supports internationalization (they begin with the letter u and contain multibyte characters). Technically speaking, the Unicode string, is a different Python data type than normal string. However, this data type supports all the same string operations.

### 3. Lists:

The Python list object is the most generic Python Data Type. Lists are positionally ordered collections of arbitrarily typed objects and can be of any length. Lists, like Strings, are also mutable, can be modified in-place by assignment to offsets as well as a variety of list method calls.

Date: 30th May, 2020 (Saturday)
Time: 10:30 AM - 11:30 AM (IST/GMT +5:30)
• This field is for validation purposes and should be left unchanged.

A list is a typical example of the mutual data type in Python. It can contain mixed data types. A list and a tuple share many common features. Because a list is a modifiable data type, it has some additional operations. A whole chapter is dedicated to the Python list.

Sequence Operations:

Lists generally support all the sequence operations for strings; the only difference is that results usually list instead of strings.

Nesting:

Nesting is perhaps the best feature of Lists, one of Python’s core data types. Lists support arbitrary nesting. They can be nested in any combination, and as deeply as required. For example, you can have a list containing a dictionary, which leads to another list, and so on. multidimensional arrays in Python are a classic application of this feature.

### 4. Dictionaries:

Python dictionaries are known as mappings. Mappings may also be described as collections of other objects, but they store objects by key instead of by relative position. mappings do not maintain any reliable left-to-right order; they simply map keys to associated values. Dictionaries, the only mapping type in Python’s core objects set, are also mutable.  These data types may be changed in-place and can grow and shrink on demand, just as lists do.

Mapping Operations:

When written as literals, dictionaries are coded in curly braces and consist of a series of “key: value” pairs. Dictionaries are useful anytime we need to associate a set of values with keys—to describe the properties of something, for instance. As an example, consider the following three-item dictionary (with keys “food,” “quantity,” and “color”):

### 5. Tuples:

A tuple is an immutable sequence Python data type. The tuple may contain mixed data types.

For example:

fruits = (“oranges”, “apples”, “bananas”)

Tuples are created using round brackets. Here we have a tuple consisting of three fruit types.

fruits = “apples”, “oranges”, “bananas”

print(fruits) # prints (‘apples’, ‘oranges’, ‘bananas’)

The tuple object may be grossly explained as a list that cannot be changed. Tuples are, in fact, sequences, like lists, but they are also immutable, like strings. Syntactically, tuples, as core Python data types, are coded in parentheses instead of square brackets, and they support arbitrary types, nesting, and the usual sequence operations:

### 6. Files:

File objects may be described as Python code’s main interface to external files on your computer. They are one of the popular core data types in Python, but without any specific literal syntax for creating them. To create a file object, one needs to call the built-in open function, passing in an external filename as a string, and a processing mode string. For example, to create an output file, you would pass in its name and the ‘w’ processing mode string to write data:

The other file object methods support additional features, offering more ways of reading and writing (read accepts an optional byte size, read line reads one line at a time, and so on), as well as other tools (seek moves to a new file position).

### 7. Other Core Types:

Other Python data types, may or may not qualify for membership, depending on how broad the category is defined to be. Sets, for example, are a recent addition to the language. Sets may be defined as containers of other objects created by calling the built-in set function, and they support the usual mathematical set operations. Sets are available as one of the standard data type of Python, since Python 2.6.

Among other data types in Python, decimal numbers (fixed-precision floating-point numbers) and Booleans (with predefined True and False objects that are essentially just the integers 1 and 0 with custom display logic), are important. Booleans have long supported a special placeholder object called None.

Want to know about Python libraries? Read my earlier post on Top 10 Python Libraries for Data Science.

Mastering Python Data Types will prepare you for a rewarding career in Python. Career opportunities in Python have multiple merits. Tremendous growth, enormous learning, and lucrative salary are some of the well-known perks. You can be part of the changing technological landscape and influence it in your own way. Add to that the magic touch of a Data Analytics course, and you are ready to rock!