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

Variables and Data Types(Python

The document provides an overview of variables and data types in Python, detailing their purpose, usage, and naming conventions. It emphasizes the importance of choosing appropriate data types and avoiding reserved keywords when naming variables. Additionally, it outlines practical applications of variables in programming, such as user input, financial calculations, and data analysis.

Uploaded by

venomiscool71
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)
9 views

Variables and Data Types(Python

The document provides an overview of variables and data types in Python, detailing their purpose, usage, and naming conventions. It emphasizes the importance of choosing appropriate data types and avoiding reserved keywords when naming variables. Additionally, it outlines practical applications of variables in programming, such as user input, financial calculations, and data analysis.

Uploaded by

venomiscool71
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/ 47

VARIABLES AND DATA

TYPES (PYTHON]
Presented by Kean Psalm Escorial
and
Johannes B. Geolina
Objectives

• Define variables and their purpose in


Python.
• Identify and use Python data types.
• Write scripts utilizing variables and data
types.
Variables
Example:

A Variable is
create when
Output:
you assign a
value to it.
Variables
Example:

Variables do not
need to be
declared with any
particular type, Output:
and can even
change type after
they have been
set.
Variables
Example:

CASTING
If you want to
specify the data
type of a variable,
this can be done
with casting.
Variables
Example:

Case-Sensitive

Variable names
are case-
sensitive.
Purpose of Variables

Variables in Python are used to


store data values, allowing you to
reference and manipulate them
throughout your code.
Purpose of Variables

A concrete example is storing a


user's input, like their name, to
personalize a greeting:
Variable Names
A variable can have a short name (like x and y) or a more descriptive
name (age, carname, total_volume).

• A variable name must start with a letter or the underscore


character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are
three different variables)
• A variable name cannot be any of the Python keywords.
Variable Names

Legal Variable Examples: Illegal Variable Examples:


Variable Names
Multi Words Variable Names

Variable names with multiple words can be hard


to read, but there are several techniques to
improve their readability:

Camel Case
Pascal Case
Snake Case
Variable Names

Camel Case
Each word, except the first, starts with a capital
letter:
Variable Names

Pascal Case
Each word starts with a
capital letter:
Variable Names

Snake Case
Each word is separated by an underscore character:
Misuse of Reserved Keywords
What Are Reserved Keywords?

Reserved keywords are special words in Python that have


predefined meanings and cannot be used as variable
names.

Examples: if, else, while, for, class, def, etc.


Misuse of Reserved Keywords
Why Are They Important?

Reserved keywords are part of Python’s syntax.


Using them as variable names causes syntax
errors.
Misuse of Reserved Keywords
Common Error Example:
Misuse of Reserved Keywords
Common Error Example:
Misuse of Reserved Keywords
Use a descriptive variable name instead
Misuse of Reserved Keywords
Replace 'def' with a valid name
Misuse of Reserved Keywords
Task: Identify and correct the misuse of
reserved keywords in this script:
Misuse of Reserved Keywords
Correct Solution:
Data Types

In programming, data types are crucial because


variables can hold various types of data, each
capable of performing different tasks.
Python provides the following built-in data types,
categorized as:
Data Types
Data Types
Data Types
Choosing Appropriate Data Types

Choosing the right data type ensures proper memory


usage, enables relevant operations, and prevents errors.
For example:
Choosing Appropriate Data Types
Choosing Appropriate Data Types
Choosing Appropriate Data Types
Choosing Appropriate Data Types
Choosing Appropriate Data Types
Group Task

Collaborate with your research team to analyze


this script, identifying the data types of the
variables used.
Group Task
Group Task
Answe
r
Script Writing

Write a Python script that performs the following tasks:


• Stores your name, age, height, and whether you are a
student in variables.
• Prints a greeting message using the stored information.
CORRECT, AN
ERROR
Objective:
Identify and correct errors related to variable
usage in Python.

Instructions:
1.Analyze the following Python script.
2.Identify the errors in variable declaration,
assignment, or usage.
3.Rewrite the corrected version of the script.
CORRECT, AN
ERROR
# Debug the following script
CORRECT, AN
# Corrected script ERROR
Real-Life Applications

Variables are foundational to all programming


tasks. Here are practical ways variables are used:

User Input and Personalization


• Store and process user-provided data.

Use Case: Personalized greetings, chatbots, or forms.


Real-Life Applications

Financial Calculations
• Track and calculate expenses, income, and
budgets.

Use Case: E-commerce platforms, billing systems.


Real-Life Applications

IoT and Device Control


• Monitor and control device states.

Use Case: Smart home systems, automation tools.


Real-Life Applications

Decision Making
• Use variables to determine conditions and
outcomes.

Use Case: Weather apps, recommendation systems.


Real-Life Applications

Data Analysis
• Store and manipulate datasets for analysis.

Use Case: Statistical tools, data visualization.


Key Takeaways
QNA
SESSION
THANK
YOU

You might also like