0% found this document useful (0 votes)
5 views20 pages

Python Data Types

This document provides an overview of Python data types, including variables, strings, integers, booleans, and floats. It explains how to identify and use these data types in coding, along with rules for naming variables. Additionally, it covers operators and the importance of comments in Python programming.

Uploaded by

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

Python Data Types

This document provides an overview of Python data types, including variables, strings, integers, booleans, and floats. It explains how to identify and use these data types in coding, along with rules for naming variables. Additionally, it covers operators and the importance of comments in Python programming.

Uploaded by

SIDRA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON

DATA TYPES
Understanding How Computers
Store Information
WHAT YOU'LL LEARN
By the end of this lesson, you will be able to:
● Identify different data types in Python
● Explain what variables do in code
● Use strings, integers,float and booleans in
examples
● Match real-world data to the right type
● Write simple code that uses correct data
types
KEY VOCABULARY

Variable: A named box holding a value. Integer: Whole numbers (e.g., 5, -10).
String: Text in quotes, like words or Boolean: True/False values for code
sentences.( e.g. “7”,”hello”) decisions.
Float: Numbers that have decimal or
fractional part (e.g. 0.14, 15.6 etc)
WHAT IS A VARIABLE?
Think of a Label
A variable is like a labeled jar where you
store something. In Python, you give it a
name and assign a value.
Example in Code
This means: Put the value "Alex" into the
variable called .
Why It Matters
Variables help programs remember and use
data later, just like remembering your score in a
game.
What are the rules of variables in Python?
Rules of Python variable:

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


character. E.g: name or full_name
● 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.
STRINGS: STORING TEXT
What’s a String?
A string is text surrounded by quotes. It can be a
name, message, or even a single letter.
Examples
In Real Life
Usernames, passwords, and text messages in
apps are all stored as strings.
Notice how both single and double quotes work:
or "cat".
INTEGERS: WHOLE NUMBERS
Counting Numbers
An integer is any whole
number—positive, negative, or
zero—without decimals.
Examples
,,,
In Code
Real-World Use
Game scores, ages, and temperatures (like
-10°C) are stored as integers.
BOOLEANS: TRUE OR FALSE
Yes or No Decisions
A boolean is a value that is either True
or false. It’s Python’s way of making
decisions.
Examples
How It’s
Used
Booleans control things like: Should the light
turn on? Is the password correct?
Think of it like a light switch—only two states!
Float: Decimal or fractional numbers
Decimal Numbers
Float, or "floating point number" is a
number, positive or negative, containing
one or more decimals
Examples
,,,
In Code

Type different decimal numbers in python code


and check the output.
Answers on the next
MATCHING DATA TO TYPES slide...

Which Type Fits? Do it yourself


Let’s match real data to the right Python Work in pairs to decide the data type for:
type: ● "Pizza" →
● Your name → String ● 42 →
● Your age → Integer ● False →
● Is today a school day? → Boolean ● "7" →
● Your favorite number → Integer ● Pi value 3.14 →
● Scientific numbers with an exponent
value"e" → Float
Do it yourself
Work in pairs to decide the data type for:
● "Pizza" → String
● 42 → Integer
● False → Boolean
● "7" → String (in quotes!)
● Pi value 3.14 → float
Discuss: Why is "7" a string but 7 an
integer?
STRING VS NUMBER Answers on the next
slide...
Which statements correctly explain why "7" is a string in Python? Choose all that
apply.

1 It stores text, even if the text looks like a number.

.
2 It’s a math problem that equals 7.

.
3 Python treats anything in quotes as text, not a number.

.
4 You can’t use '7' in math like regular numbers unless you convert it.

.
STRING VS NUMBER
Which statements correctly explain why "7" is a string in Python? Choose all that
apply.

1 It stores text, even if the text looks like a number.

.
2 It’s a math problem that equals 7.

.
3 Python treats anything in quotes as text, not a number.

.
4 You can’t use '7' in math like regular numbers unless you convert it.

.
Types of operator python support:
● Arithmetic (+,-,*, /)
● Comparison (<,>)
● Assignment (=) and
● Logical (AND, OR and NOT)
Arithmetic Operator
Arithmetic operators are used with numeric
values to perform common mathematical
operations
x = 15
y = 4

print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
print(x ** y)
print(x // y)
Assignment Operators
Assignment operators are used to assign values to variables.

Output:
5
8
2
Comparison Operators
Comparison operators are used to compare two values
Logical Operators
Logical operators are used to combine conditional statements
Example:
x=5

Output:
True
True
False
Comment in pyhton
How to write comments in Python.
Comments can be used to explain Python code. Comments starts with a #,
and Python will ignore them.
Example:
#This is a comment.
WHAT WE LEARNED
You now know how Python uses different data types
to store information:
● Variables are named containers
● Strings hold text
● Integers are whole numbers
● Booleans are True/False values
● Float are decimal numbers
These building blocks help you write real code!

You might also like