Learn practical skills, build real-world projects, and advance your career

Next Unit

Unit-1

1. Core 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

Python’s Core Data Types include:

1.Numbers

2.Strings

3.Lists

4.Dictionaries

5.Tuples

6.Files

Other types include: Sets, types, None, Booleans

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:

image.png

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 tuple
image-2.png

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.

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.

image-2.png

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.

image-3.png

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’)

image-4.png

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:

python files
image-5.png

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.

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.

Examples

#int
1234
1234
#float
123.0
123.0
#string
"string"
'string'