🔥 Welcome to my blog! Latest updates available now. Visit daily! 🔥 🔥 Click Here for Latest Updates – Visit My Blog 🔥
🔥 Latest Updates 📊 GP Grade Finder 📢 Government Services Info 🆕 New Schemes Updates

Data Types in Python Programming

Data Types

Ø  Data Type represents the type of data present inside a variable.

Ø  In Python we are not required to specify the type explicitly.

Ø  Based on value provided, the type will be assigned automatically.

Ø  Hence Python is Dynamically Typed Language.

Python contains the following inbuilt data types

1. int

4.bool

7.bytearray

10.tuple

13.dict

2. float

5.str

8.range

11.set

14. None

3.complex

6.bytes

9.list

12.frozenset

 


Note: Python contains several inbuilt functions

1. type():To check the type of variable

2. id():To get address of object

3. print():To print the value.

In Python everything is an object

int Data Type:

Ø  We can use int data type to represent whole numbers (integral values)

Example: >>> a=10                            >>> a=40+60

               >>> type(a)                          >>> a

               <class 'int'>                          100

Note:

Ø  In Python2 we have long data type to represent very large integral values.

Ø  But in Python3 there is no long type explicitly and we can represent long values also by using int type only.

We can represent int values in the following ways

1. Decimal form

2. Binary form

3. Octal form

4. Hexa decimal form

1. Decimal form(base-10):

Ø  It is the default number system in Python.The allowed digits are: 0 to 9

Example : >>> d=528                          >>> d=1234a

                  >>> d                                >>> d=1234a

                        528                                     File "<stdin>", line 1    d=1234a         

                                                                                                             ^SyntaxError: invalid syntax

  2. Binary form(Base-2);

Ø  The allowed digits are: 0 & 1.Literal value should be prefixed with Ob or OB

Example :>>> b=0b1111                    >>> b=0B123

                >>> b                                 File "<stdin>", line 1    b=0B123        

                       15                                ^SyntaxError: invalid digit '2' in binary literal3

3. Octal Form(Base-8);

Ø  The allowed digits are: 0 to 7,Literal value should be prefixed with 00 or 00.

Example: >>> o=0o1234      >>> o=0O143

                 >>> o                    >>> o

                        668                       99

              >>> o=0O148

                     File "<stdin>", line 1    o=0O148

                                                                        ^SyntaxError: invalid digit '8' in octal literal

4. Hexa Decimal Form(Base-16);

Ø  The allowed digits are: 0 to 9, a-f (both lower and upper cases are allowed) Literal value should be prefixed with Ox or OX

Example:>>> h=0x123f                            >>> h=0X123e

               >>> h                                        >>> h

                      4671                                           4670

>>> h=0X14h

  File "<stdin>", line 1    h=0X14h

                                                     ^SyntaxError: invalid syntax

Note: Being a programmer we can specify literal values in decimal, binary, octal and hexa decimal forms. But PVM will always provide values only in decimal form.

2.float Data Type:

Ø  We can use float data type to represent floating point values (decimal values)

Example :.>>> f=1.234                >>> f = 1.2e3      >>> f = 3.4E2    >>> type(f) 

               >>> f                            >>> f                     >>> f                      <class 'float'>

                      1.234                             1200.0                   340.0

Ø  We can also represent floating point values by using exponential form (scientific notation

Ø  Instead of 'e' we can use 'E'

Ø  The main advantage of exponential form is we can represent big values in less memory.

Note:

Ø  We can represent int values in decimal, binary, octal and hexa decimal forms. But we can represent float values only by using decimal form.

>>> f=0B11.01

  File "<stdin>", line 1    f=0B11.01         

                                                    ^Syntax Error: invalid syntax

x = 35e3

y = 12E4

z = -87.7e100

print(type(x))     #<class 'float'>

print(x)              #35000.0

print(type(y))   #<class 'float'>

print(y)           #120000.0

print(type(z))   #<class 'float'>

print(z)            #-8.77e+101

3. complex Data Type:

Ø  A complex number is of the form

a           +     bj

Ø  Real Part Imaginary Part

Ø  a and b contain integers or floating point values

Examples :3+5j 10+5.5j  0.5+0.1j

Ø  In the real part if we use int value then we can specify that either by decimal,octal,binary or hexa decimal form.

Ø  But imaginary part should be specified only by using decimal form.

>>> a=0B11+5j

 >>> a

 (3+5j)

 >>> a=3+0B11j

 Syntax Error: invalid syntax

Ø  Even we can perform operations on complex type values.

1) >>> a=10+1.5j

 2) >>> b=20+2.5j

 3) >>> c=a+b

4) >>> print(c)

5) (30+4))

6) >>> type(c)

7) <class 'complex'>

Note: Complex data type has some inbuilt attributes to retrieve the real part and imaginary part

                                c=10.5+3.6j

c.real==>10.5                                 c.imag==>3.6

Ø  We can use complex type generally in scientific Applications and electrical engineering Applications.

4. bool Data Type:

Ø  We can use this data type to represent boolean values. The only allowed values for this data type are:True and False

Ø  Internally Python represents True as 1 and False as 0

b=True

type(b)

 =>bool

a=10

b=20

c=a<b

print(c)==>True

True+True==>2

True-False==>1

5. str Data Type:

Ø  str represents String data type.

Ø  A String is a sequence of characters enclosed within single quotes or double quotes.

s1='siddu' s1="siddu"

Ø  By using single quotes or double quotes we cannot represent multi line string literals.

s1="siddu

                                 soft"

Ø  For this requirement we should go for triple single quotes("") or triple double quotes(""")

            s1=’’’siddu soft’’’   s1="""siddu soft"""

Ø  We can also use triple quotes to use single quote or double quote in our String.

             ""This is " character"" 

             'This is" Character'

Ø  We can embed one string in another string ""This "Python class very helpful" for java students""

ü  In Python the following data types are considered as Fundamental Data types

             1. int      2. float          3. complex                   4. bool             5 .str

ü  In Python, we can represent char values also by using str type and explicitly char type is not available.

Example:

 >>> c='a'

 >>> type(c)

 <class 'str'>

ü  long Data Type is available in Python2 but not in Python3. In Python3 long values also we can represent by using int type only.

ü  In Python we can present char Value also by using str Type and explicitly char Type is not available.

Python Versions

 

Version

Release Date

Important Features

Python 0.9.0

February 1991

Classes with inheritance exception handling, Functions, Modules

Python 1.0

January 1994

Functional programming tools (lambda, map, filter and reduce),Support for complex numbers, Functions with keyword arguments

Python 2.0

October 2000

List comprehension, Support for Unicode. Unification of data types and classes

Python 2.7.0

July 2010

Python 3

December 2008

Backward incompatible, print keyword changed to print() function, raw_input() function depreciated, Unified str/Unicode types, Utilities for automatic conversion of Pytthon 2.x code

Python 3.6

December 2016

Python 3.6.5

March 2018

Python 3.7.0

May 2018

New C API for thread-local storage, Built-in breakpoint(),Data classes, Context variables

Python 3.8

October 2019

Assignment Expression, Positional-only parameters, Parallel file system cache for compiled byte code files

Python 3.9

October 2020

Dictionary Merge & Update Operators ,New removeprefix() and removesuffix() string methods, Builtin Generic Types

Python 3.10

 

October 4, 2021

Modules such as graphlib for working with graphs and zoneinfo for working with time zones.

Python 3.11

October 24, 2022

Modules such as asyncio, contextlib, dataclasses

Features of Python

 

1. Simple and easy to learn:

Ø   Python is a simple programming language. When we read Python program, we can feel like reading      English statements.

Ø The syntaxes are very simple and only 30+ keywords are available.

Ø  When compared with other languages, we can write programs with very less number of lines. Hence      more readability and simplicity.

Ø  We can reduce development and cost of the project.

2. Freeware and Open Source:

Ø  We can use Python software without any license and it is freeware.

Ø  Its source code is open, so that we can customize based on our requirement.

Ø  Ex: Jython is customized version of Python to work with Java Applications.

3. High Level Programming language:

Ø  Python is high level programming language and hence it is programmer friendly language.

Ø  Being a programmer we are not required to concentrate low level activities like memory management    and security etc….

4. Platform Independent:

Ø  Once we write a Python program,it can run on any platform without rewriting once again.

Ø  Internally PVM is responsible to convert into machine understandable form.

 5. Portability:

Ø  Python programs are portable. That is we can migrate from one platform to another platform very         easily.

Ø  Python programs will provide same results on any platform.

6. Dynamically Typed:

Ø  In Python we are not required to declare type for variables.

Ø  Whenever we are assigning the value, based on value, type will be allocated automatically.

Ø  Hence Python is considered as dynamically typed language.

Ø  But Java, C  are Statically Typed Languages because we have to provide type at the beginning only.

Ø  This dynamic typing nature will provide more flexibility to the programmer.

7. Both Procedure Oriented and Object Oriented:

Ø  Python language supports both Procedure oriented (like C, pascal etc) and object oriented (like C++, Java) features.

Ø  Hence we can get benefits of both like security and reusability etc

8. Interpreted:

Ø  We are not required to compile Python programs explicitly. Internally Python interpreter will take care that compilation.

Ø  If compilation fails interpreter raised syntax errors. Once compilation success then PVM (Python Virtual Machine) is responsible to execute.

9. Extensible:

Ø  We can use other language programs in Python. The main advantages of this approach are:

Ø  We can use already existing legacy non-Python code

Ø  We can improve performance of the application

10. Embedded:

Ø  We can use Python programs in any other language programs.

Ø  That is we can embed Python programs anywhere.

11. Extensive Library:

Ø  Python has a rich in-built library.

Ø  Being a programmer we can use this library directly and we are not responsible to implement the functionality.

Flavors of Python

1. CPython:

It is the standard flavor of Python. 

It can be used to work with C language Applications

2. Jython or Python:

It is for Java Applications.

It can run on JVM

3. IronPython:

It is for C#.Net platform

4. PyPy:

The main advantage of PyPy is performance will be improved because JIT compiler is available inside PVM.

5. RubyPython

For Ruby Platforms

6. Anaconda Python

It is specially designed for handling large volume of data processing.

à°†ంà°§్à°°à°ª్à°°à°¦ేà°¶్‌à°²ో సదరం సర్à°Ÿిà°«ిà°•ేà°Ÿ్ à°•ోà°¸ం à°Žà°¦ుà°°ుà°šూà°¸్à°¤ుà°¨్à°¨ à°¦ిà°µ్à°¯ాంà°—ులకు à°¸్à°²ాà°Ÿ్ à°¬ుà°•ింà°—్ à°…à°ª్‌à°¡ేà°Ÿ్.

à°‡ంతకుà°®ుంà°¦ు వరకు SADAREM Slot Booking à°ª్à°°à°•్à°°ిà°¯ à°¸్వర్à°£ à°—్à°°ాà°®ం à°¸్వర్à°£ à°µాà°°్à°¡ు à°¦్à°µాà°°ా à°®ాà°¤్à°°à°®ే à°…ంà°¦ుà°¬ాà°Ÿుà°²ో à°‰ంà°¡ేà°¦ి. à°ª్à°°à°¸్à°¤ుà°¤ం à°ª్రజలకు మరింà°¤ à°¸ౌà°•à°°్యవం...