0% found this document useful (0 votes)
22 views92 pages

11-unit1chapter03datahandling-180823043256

Uploaded by

Rahul GITAM
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)
22 views92 pages

11-unit1chapter03datahandling-180823043256

Uploaded by

Rahul GITAM
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/ 92

CHAPTER - 03

DATA HANDLING
XI
Computer Science (083)
Board : CBSE
4.1 Unit 1:
Programming and Computational Thinking (PCT-1)
Courtesy CBSE
4.1 Unit I
Programming and Computational
Thinking (PCT-1)
(80 Theory + 70 Practical)

Prepared by
Praveen M Jigajinni
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)

Department of Computer Science, Sainik School Amaravathinagar

Cell No: 9431453730 Email – [email protected]


Courtesy CBSE
CHAPTER - 03
DATA HANDLING
INTRODUCTION
INTRODUCTION

Data can be of many types


e.g. character, string, integer, real etc.

Python like any other


language provides ways and facilities to
handle different types of data by
providing data types.
PYTHON DATA TYPES
PYTHON DATA TYPES

What is Data type?

DATA TYPES are means to identify


the type of data and associated
operations of handling it.
PYTHON DATA TYPES
Dictionary Integers

Floating
None Data
Point
Numbers

Types

List Complex
Numbers

Tuples Strings
NUMBERS
NUMBERS

The numbers can be represented


in the python as:
(i) Integers.
(ii) Floating point Numbers.
(iii) Complex Numbers.
(I) INTEGERS
(i) INTEGERS

Integers numbers are whole


numbers (without any fractional part).
For example: 123,-789 etc.
TYPES OF INTEGERS

There are two types of integers:


(i) Integers (Signed).
(ii) Booleans.

Types
Signed
Intege
rs

Bool
of eans

Integers
TYPES OF INTEGERS
(i) INTEGERS (SIGNED)

Integers can be of any


length. Its only limited by the memory
available.

It’s a signed representation,


i.e., the integers can be positive or
negative.
(ii) BOOLEANS
(ii) BOOLEANS

Boolean data types are the


truth values, i.e., True form or False
form.

Boolean data type is a one kind of


integer type they can be represented in
the integer form i.e., 0 and 1.
(ii) BOOLEANS

practically one can execute as

>>>bool(0)
will give result as false

>>>bool(true)
will produce 1 result.
str ( ) Function
str ( ) Function

str ( ) function coverts a value to


string type.

>>>str(false)
will give string type result ‘false’

>>>str(true)
will produce string type ‘true’
result.
(ii) FLOATING POINT NUMBERS
(ii) FLOATING POINT NUMBERS

A numbers containing
fractional part is called floating point
number.
for example: 93.452
Floating point numbers can be
written in two forms.
Note: Floating point numbers have
precision of 15 Digits( double precision)
in python.
(ii) FLOATING POINT NUMBERS

Fractional Exponent
Form Notation

Floating
Point
Numbers

Note: Floating point numbers have precision of


15 Digits( double precision) in python.
Advantages of Floating
Point Numbers
(ii) Advantages of Floating Point Numbers

1. They can represent range of


values between the integers.
2. They can represent a greater extent/
range of values.

Note: Floating point numbers have precision of


15 Digits( double precision) in python.
Disadvantages of Floating
Point Numbers
(ii) Disadvantages of Floating Point Numbers

Floating-point operations are


usually slower than integer operations.

Note: Floating point numbers have precision of


15 Digits( double precision) in python.
(iii) COMPLEX NUMBERS
(iii) COMPLEX NUMBERS

A complex number is
a number that can be expressed in the
form a + bi,
where,
a and b are real numbers, and
i is called an imaginary number.
For the complex number a + bi, a is
called the real part, and b is called
the imaginary part.
(iii) COMPLEX NUMBERS
(iii) COMPLEX NUMBERS
(iii) COMPLEX NUMBERS
(iii) COMPLEX NUMBERS
(iii) COMPLEX NUMBERS
COMPLEX NUMBERS IN PYTHON
COMPLEX NUMBERS IN PYTHON

complex number is made up of real and


imaginary parts.

Real part is a float number, and imaginary


part is any float number multiplied by
square root of -1 which is defined as j.
COMPLEX NUMBERS IN PYTHON

>>> no=5+6j

>>> no.real o/p 5.0

>>> no.imag o/p 6.0

>>> type(no)

<class 'complex'>
COMPLEX NUMBERS IN PYTHON

Python library also has complex()


function, which forms object from two
float arguments
>>> no=complex(5,6)
>>> no (5+6j)
>>> no.real o/p 5.0
>>> no.imag o/p 6.0
>>> type(no)
<class 'complex'>
Data Type Range
Data Type Range

Data Type Range


Integers Unlimited subject to
availability of memory
Booleans True ( 1 ), False ( 0 )
Floating Point Unlimited subject to
Numbers availability of memory
and depends on machine
architecture.
Complex Numbers Same as float type
UNICODE
What is UNICODE?

Unicode provides a unique


number for every character,
no matter what the platform,
no matter what the program,
no matter what the language.
UNICODE HISTORY
UNICODE HISTORY

The origins of Unicode date to


1987, when Joe Becker from Xerox with Lee
Collins and Mark Davis from Apple, started
investigating the practicalities of creating a
universal character set.
UNICODE HISTORY

With additional input from Peter


Fenwick and Dave Opstad, Joe Becker
published a draft proposal for an
"international/multilingual text character
encoding system in August 1988,
tentatively called Unicode". He explained
that the name 'Unicode' is intended to
suggest a unique, unified, universal
encoding".
UNICODE ADOPTION
UNICODE ADOPTION

It has been adopted by all


modern software providers and now allows
data to be transported through many
different platforms, devices and
applications without corruption.
operating systems, search engines,
browsers, laptops, and smart phones—plus
the Internet and World Wide Web (URLs,
HTML, XML, CSS, JSON, etc.) using unicode
UNICODE IMPLIMENTATION
UNICODE IMPLIMENTATION

Unicode can be
implemented by different character
encodings. The Unicode standard
defines UTF-8, UTF-16, and UTF-32, and
several other encodings are in use. The
most commonly used encodings are UTF-8,
UTF-16 and UCS-2, a precursor of UTF-16.
STRINGS
STRINGS

Like many other popular


programming languages, strings in
Python are arrays of bytes representing
Unicode characters. However, Python does
not have a character data type, a single
character is simply a string with a length of
1. Square brackets can be used to access
elements of the string.
How to create a string in Python?
STRINGS

How to create a string in Python?

Strings can be created by enclosing


characters inside a single quote or double
quotes. Even triple quotes can be used in
Python but generally used to represent
multiline strings and docstrings.
REPRESENTATION OF STRING
REPRESENTATION OF STRING
>>> s = “Hello Python”
This is how Python would index the string:

Backward Indexing

Forward Indexing
STRINGS – Programming Example
STRINGS - Example

Output Next Slide...


STRINGS - Example
How to access characters in a string?
STRINGS

How to access characters in a string?

We can access individual characters


using indexing and a range of characters
using slicing. Index starts from 0. Trying to
access a character out of index range will
raise an IndexError. The index must be an
integer. We can't use float or other types,
this will result into TypeError.
STRINGS

How to access characters in a string?

Python allows negative indexing for


its sequences.

The index of -1 refers to the last item,


-2 to the second last item and so on. We
can access a range of items in a string by
using the slicing operator (colon).
STRINGS – Programming Example
STRINGS
STRINGS
SLICING STRINGS EXAMPLES

For example: >>>p = “Program”


>>>“Program”[3:5] >>>p [4:]
will result in: ‘ram’
‘gr ’
>>>p = “Program”
>>>p [3:6]
>>>“Program”[3:6] ‘gra’
will yield:
‘gra’
SLICING STRINGS EXAMPLES

For example:

>>>p = “Program”
>>>p [:4]
‘Prog’
Index Error!
STRINGS –Index error
MUTABLE AND IMMUTABLE OBJECTS
IN PYTHON
MUTABLE AND IMMUTABLE OBJECTS

What is Mutable Object?

In object-oriented programming
language , an immutable object is an object
whose state/ values can be modified after its
creation.
In short the an object / variable, for
which we can change the value is
called mutable object or mutable variable.

For example : Lists are mutable in nature.


MUTABLE AND IMMUTABLE OBJECTS

What is Immutable Object?

In object-oriented programming
language, an immutable object is an object
whose state/ values can not be modified after
it’s creation.
In short an object or a variable , for
which we can not change the value
is immutable object or immutable variable.

For example : Tupels are immutable in nature.


TUPLES
TUPLES

What is Tuples?

Lists and tuples can be thought of as


generic "buckets" with which to hold an
arbitrary number of arbitrary Python objects.
TUPLES

What is Tuples or Tuple?

Tuples are the type of data it is a sequence


of immutable Python objects. Tuples are
sequences, just like lists. The differences
between tuples and lists are, the tuples cannot
be changed unlike lists and tuples use
parentheses, whereas lists use square brackets.
Creating a tuple is as simple as putting different
comma-separated values
EXAMPLES ON TUPLES
TUPLES EXAMPLE

DEFINING TUPLES WITHOUT ( )


TUPLES EXAMPLE
DEFINING TUPLES WITH ( )
TUPLES EXAMPLE – Accessing individual
elements using index number in [ ]
LISTS
LISTS

A list is a data type that can be used to store


any type and number of variables and information.
Lists are mutable in nature.

General format of list is :


my_list = [item_1, item_2, item_3]

Python also allows creation of an empty list:


my_list = []
For Example
colors = ["Orange" , "red" , "Green" , "White“]
LISTS EXAMPLE
LISTS

Note: Lists are mutable in nature.


PRECEDENCE OF AN OPERATORS
PRECEDENCE OF AN OPERATOR

Operator Description
** Exponentiation (raise to the
power)
~+- Complement, unary plus and
minus (method names for the last
two are +@ and -@)
* / % // Multiply, divide, modulo and floor
division
PRECEDENCE OF AN OPERATOR

Operator Description
+- Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'td>
^| Bitwise exclusive `OR' and regular
`OR'
<= < > >= Comparison operators
<> == != Equality operators
PRECEDENCE OF AN OPERATOR

Operator Description
= %= /= //= Assignment operators
-= += *= **=
is is not Identity operators
in not in Membership operators
not or and Logical operators
EXAMPLE ON

PRECEDENCE OF AN OPERATOR
PRECEDENCE OF OPERATOR EXAMPLE
PRECEDENCE OF OPERATOR EXAMPLE
Any Questions Please
THANK YOU

You might also like