0% found this document useful (0 votes)
2 views

5. Summary of Datatypes in Python3

The document provides an overview of various data types in Python 3, including their descriptions, mutability, and examples. It covers types such as int, float, complex, bool, str, bytes, bytearray, list, tuple, set, frozenset, dict, and None. Additionally, it discusses escape characters in strings and the convention for defining constants in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

5. Summary of Datatypes in Python3

The document provides an overview of various data types in Python 3, including their descriptions, mutability, and examples. It covers types such as int, float, complex, bool, str, bytes, bytearray, list, tuple, set, frozenset, dict, and None. Additionally, it discusses escape characters in strings and the convention for defining constants in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Summary of Datatypes in Python3

Datatype Description Is Immutable Example


Int We can use to represent Immutable >>> a=10
the whole/integral >>> type(a)
numbers <class 'int'>
Float We can use to represent Immutable >>> b=10.5
the decimal/floating point >>> type(b)
numbers <class 'float'>
Complex We can use to represent Immutable >>> c=10+5j
the complex numbers >>> type(c)
<class 'complex'>
>>> c.real
10.0
>>> c.imag
5.0
Bool We can use to represent Immutable >>> flag=True
the logical values(Only >>> flag=False
allowed values are True >>> type(flag)
and False) <class 'bool'>
Str To represent sequence of Immutable >>> s='durga'
Characters >>> type(s)
<class 'str'>
>>> s="durga"
>>> s='''Durga Software Solutions
... Ameerpet'''
>>> type(s)
<class 'str'>
bytes To represent a sequence Immutable >>> list=[1,2,3,4]
of byte values from 0-255 >>> b=bytes(list)
>>> type(b)
<class 'bytes'>
bytearray To represent a sequence Mutable >>> list=[10,20,30]
of byte values from 0-255 >>> ba=bytearray(list)
>>> type(ba)
<class 'bytearray'>
range To represent a range of Immutable >>> r=range(10)
values >>> r1=range(0,10)
>>> r2=range(0,10,2)
list To represent an ordered Mutable >>> l=[10,11,12,13,14,15]
collection of objects >>> type(l)
<class 'list'>
tuple To represent an ordered Immutable >>> t=(1,2,3,4,5)
collections of objects >>> type(t)
<class 'tuple'>
set To represent an unordered Mutable >>> s={1,2,3,4,5,6}
collection of unique >>> type(s)
objects
<class 'set'>
frozenset To represent an unordered Immutable >>> s={11,2,3,'Durga',100,'Ramu'}
collection of unique objects >>> fs=frozenset(s)
>>> type(fs)
<class 'frozenset'>
dict To represent a group of Mutable >>>
key value pairs d={101:'durga',102:'ramu',103:'hari'}
>>> type(d)
<class 'dict'>

None Data Type:

None means Nothing or No value associated.


If the value is not available,then to handle such type of cases None
introduced. It is something like null value in Java.
Eg:
def m1():
a=10

print(m1())
None

Escape Characters:
In String literals we can use esacpe characters to associate a special meaning.

1) >>> s="durga\nsoftware"
2) >>> print(s)
3) durga

5) >>> s="durga\tsoftware"
6) >>> print(s)
7) durga software
The following are various important escape characters in Python

1) \n==>New Line
2) \t===>Horizontal tab
3) \r ==>Carriage Return
4) \b===>Back space
5) \f===>Form Feed
6) \v==>Vertical tab
7) \'===>Single quote
8) \"===>Double quote
9) \\===>back slash symbol
....

Constants:
Constants concept is not applicable in Python.
But it is convention to use only uppercase characters if we don’t want to

change value. MAX_VALUE=10

It is just convention but we can change the value.

You might also like