You are on page 1of 21

UNDERSTANDING

DATA
HOW DOES DATA STRUCTURES MAKE YOUR PROGRAM
WORKS EFFECTIVELY?
JUMBLED
WORDS
1. reterrnterepi
2. tada
3. pytes
4. eraitlls
5. iaevarsbl
OBJECTIVES
After studying this lesson, you should be able to:
learn how data is represented in Python,
list the common data types,
specify data, and
perform basic operations.
WHAT IS AN
INTERPRETER?
an interpreter is a computer program that directly executes
instructions written in a programming or scripting language.
Interpreters are sometimes used during the development of a
program, when a programmer wants to add small sections at a time
and test them quickly. Interpreters are also often used in education
because they allow students to program interactively.
It is not time-consuming
USING THE INTERPRETER
LAUNCHING IDLE
OPENS UP THE
PYTHON SHELL.

IN PYCHARM, THE PYTHON SHELL


CAN BE ACCESSED READILY FROM
WITHIN PYCHARM THROUGH THE
PYTHON CONSOLE TOOL
WINDOW.
TO RESTART THE SHELL, PRESS CTRL + F6 IN
IDLE OR PRESS CTRL + F5 IN PYCHARM.
DATA AS OBJECTS
TO WRITE EFFECTIVE CODE, YOU NEED TO KNOW HOW THE PROGRAMMING
LANGUAGE HANDLES AND MANAGES DATA.
Python follows this “data as objects” analogy and
treats data accordingly. Each object bears the Try this out in the interpreter.
following information: Enter each of the following
lines:
an identity (or ID), which tells it apart from other
objects (usually the object’s location in the
computer’s memory)
a type, which determines what kind of value it
can have
a corresponding value
ID() FUNCTION WHEN USING FUNCTIONS, WE PLACE THE
OBJECT WE WANT TO BE PROCESSED
RUN THE WITHIN THE PARENTHESES.
FOLLOWING LINES: THE INTERPRETER SHOULD RETURN
AN INTEGER VALUE FOR EACH,
SIGNIFYING THEIR LOCATION IN YOUR MEMORY.
HERE IS A LIST OF THE
COMMON DATA TYPES AND
THEIR RESPECTIVE USES.
Data Types

ANY DATA THAT YOU


WILL BE WORKING
WITHIN PYTHON
WILL HAVE A
CORRESPONDING DATA
TYPE.
IN THE INTERPRETER,
ENTER:

PYTHON SHOULD RETURN THE DATA


TYPES OF EACH I.E. X IS A STRING AND
Y IS AN INTEGER.
MUTABILITY
refers to whether the
value of the object can be
changed (mutable) including
sets, list and dictionaries.

not (immutable) or not


changeable such as:. Integer,
float, string, Boolean, tuple,
and frozenset data are
immutable.
LET’S TRY CHANGING THE DATA OF ONE OF THE
VARIABLES. ENTER THE FOLLOWING CODE.
CHECK WHAT DATA X CONTAINS USING THE
PRINT() FUNCTION. Now let’s try doing something
similar to a mutable data type
Let’s check the IDs of the
such as a list. Let’s create
following:
a simple list and assign it to a
variable.

CHECK THE IDS OF BOTH A AND B.


pop() function- effectively
remove the last item
from the list and returened its
value
>>> a.pop() >>> id(a)
3 1745367728256
>>> print(a)
>>> id(b)
[1,2]
1745367728256
>>>print(b)
[1,2]
See how they both still have the same
value refer to the same object in the
memory
It is good to know how these properties can affect
the program. For instance, immutable objects are
considered “thread-safe” in cases when the
computer is capable of multithreading or running
multiple processes at once. This ensures that the
code will work even if the objects are passed on
across threads. Immutability also promotes clarity
and exactness in the code, as every immutable
object is guaranteed to remain the same as the
program runs.
SPECIFYING DATA VALUES
A literal is a direct way to
specify a value.

Variables are among the


fundamental
programming concepts
that you must grasp. We Must begin with a letter or underscore and not a
do not have to declare a digit
variable’s data type May only contain the following characters
{ Lower case letters (a-z)
explicitly when creating
{ Uppercase letters (A-Z)
one in Python.
{ Digits (0-9)
Python has several rules
{ Underscore (_)
on how you can name a
Is case-sensitive, meaning var, VAR, and Var
variable:
would be considered unique names
Can’t be one of Python’s keywords
To get a list of Python’s keywords, run
help(‘keywords’) in the interpreter.
To assign a variable to an
object, we use the equal
sign (=).
The following code example would print the data type of x,
identify each data type.
Self-Reflection

1. What part of your identity do you think people


first notice about you?
2. Why is knowing our identity important?
PERFORMANCE TASK
Using Python IDLE, write a line of code that does the following:
Save your output in our flashdrive and name the file
(CompleteName)Datatype.py
1. Assign the variable hero to the text string value 'Apolinario
Mabini'
2. Display the value of the variable hero
3. Reassign the variable hero to the text string value
'Melchora Aquino'
4. Check the ID of the variable hero
5. Check the data type of the object to which the variable hero
is associated
THANK YOU
FOR LISTENING!
Do you have any questions for
me?

You might also like