0% found this document useful (0 votes)
1 views12 pages

Python Unit 1(Lecture 4)

The document covers the basics of Python data types, including Numbers, Strings, Lists, Tuples, Sets, and Dictionaries. It explains the characteristics of each type, such as mutability and how they are represented in Python. Additionally, it distinguishes between mutable and immutable types, highlighting their behaviors in programming.

Uploaded by

upasanabishtiitm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views12 pages

Python Unit 1(Lecture 4)

The document covers the basics of Python data types, including Numbers, Strings, Lists, Tuples, Sets, and Dictionaries. It explains the characteristics of each type, such as mutability and how they are represented in Python. Additionally, it distinguishes between mutable and immutable types, highlighting their behaviors in programming.

Uploaded by

upasanabishtiitm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Basics of Python

Programming
(UNIT-1)
Lecture-4
Data Types
• Data types are means to identify type of data and set of valid operations
for it.
• Python offers following built-in core data types:
 Numbers
 String
 List
 Tuple
 Dictionary
Core Data
Types

Numbers Set None Sequences Mappings

Floating
Integer Complex Strings Dictionary
Point

Boolean Tuple

List
Numbers
• Python offers following data types to store and process different types of
numeric data:
 Integer
 Integers(signed)
 Booleans

 Floating Point Numbers

 Complex Numbers
• Integers: There are two types of integers in Python.

i. Integers(Signed): It is the normal integer representation of whole


numbers. Python provides single data type (int) to store any integer,
whether big or small.
It is signed representation i.e., the integers can be positive as well as
negative.
ii. Boolean: These represent the truth values False and True. The Boolean
type is a subtype of plain integers, and Boolean values False and True
behave like the values 0 and 1, respectively.
• Floating Point Numbers: In Python, floating point numbers represent
machine-level double precision floating point numbers(15 digit precision).
The range of these numbers is limited by underlying machine architecture
subject to available (virtual) memory.

• Complex Numbers: Python represents complex numbers in the form A+Bj.


Complex numbers are a composite quantity made of two parts: the real
part and the imaginary part, both of which are represented internally as
float values(floating point numbers).
z.real gives the real part
z.imag gives the imaginary part as a float, not as a complex value.
String
• A Python string is a sequence of characters and each character can be
individually accessed using its index.
• A string can hold any type of character i.e., letters, numbers and special
characters of any scripted language.
• Following are all legal strings in Python:
• ”abcd”, ”1234”, ”$%^&”, ”????”
Lists
• A list in Python represents a group of comma-separated values of any
datatype between square brackets.
E.g., [1,2,3,4,5]
[‘a’, ’e’, ’i’, ’o’, ’u’]
[’Neha’, 102,79.5]
• In list too, the values internally are numbered from 0(Zero) onwards.
• Values of type list are mutable i.e., changeable- one can
change/add/delete a list’s elements.
Tuple
• Tuples are represented as group of comma-separated values of any
data type within parenthesis e.g., following are some tuples:
p=(1,2,3,4,5)
q=(2,4,6,8)
r=(‘a’, ’e’, ’i’, ’o’, ’u’)
h=(7, 8, 9, ’A’, ’B’, ’C’)
• Values of type Tuple are immutable i.e., non-changeable; one cannot
make changes to a tuple.
Set
• A set is a mutable data type which is created like lists , but with { }. It can
take values of different types but cannot contain mutable elements and
duplicate entries.
e.g., Set1={1, 2, 3, 4}
• set can’t have duplicate values
e.g., Set1 = {1,2,1,3,4}
print(Set1)
output: {1,2,3,4}
• No order is preserved.
therefore, elements can’t be accessed using index unlike list.
Dictionaries
• The dictionary is an unordered set of comma-separated key: value pairs,
within a dictionary, no two keys can be the same(i.e., there are unique
keys within a dictionary). For instance, following are some dictionaries:
{’a’: 1, ’e’:2, ’i’:3, ’o’:4, ’u’:5}

• Dictionaries are mutable data type.


Mutable and Immutable Types
• The Immutable types are those that can never change their value in place.
In Python, the following types are immutable:
Integers
Floating Point Numbers
Booleans
Strings
Tuples
• In Immutable types, the variable names are stored as references to a
value-object. Each time you change the value, the variable’s reference
memory address changes.

You might also like