0% found this document useful (0 votes)
7 views8 pages

Python Homework

The document provides an overview of variables in Python, explaining their purpose as placeholders for storing information and outlining naming rules. It details various data types including numbers, strings, tuples, booleans, and composite data types like arrays and unions. Additionally, it introduces operators used to perform operations on values and variables, with examples for each type of operator.

Uploaded by

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

Python Homework

The document provides an overview of variables in Python, explaining their purpose as placeholders for storing information and outlining naming rules. It details various data types including numbers, strings, tuples, booleans, and composite data types like arrays and unions. Additionally, it introduces operators used to perform operations on values and variables, with examples for each type of operator.

Uploaded by

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

PYTHON HOMEWORK

Variable

A variable n python is known as a placeholder that


is used to store information that you want python
to retrieve or recall later when you are coding and
need to complete an action.
A variable can be used as a reference that can be
manipulated in the process of a program execution.
A variable is a name that has been given value
Rules when naming a variable
The variable name can only contain letters, digits,
underscore
The variable name cannot begin with a digit
A Variable name is known to be case sensitive
You should avoid using python keywords (e.g. If,
else, for) as a variable name
Data types

Types of variables
Numbers which can be as an integer or a float
String which can be
written with a single
quote or double
quotes
Mixing the operators
with numbers and a
string will not work

 Tuple
A tuple is a collection of objects that are separated
by a comma, once a tuple is created it cannot be
modified
 Boolean
This is a data type that can only have one possible
value which is true or false.it is used to represent
the truth values of expression

 String(s)
A string represents textual data, it is a sequence of
characters a string contains numbers, symbols or
letters

 Integer
Int, or integer, is a whole number, positive or negative, without
decimals, of unlimited length.
 Float

Float is a number with decimal points e.g numbers like


133.5, 2897.11, and 3571.213, whereas real numbers like
56, 2, and 33 are called integers.
 COMPOSITE DATA TYPES

Composite data type is a mixture of primitive and


other types of data this includes the array, lists etc.
composite data type can also be known as a
complex data type
 Array
An array is known as the arrangement of data, it is
also a collection of elements that contains the
same data type. Each element in an array can be
identified by an index, an index is used to access
an element value.
Using an array is an advantage as it can allow you
to store multiple values in one variable, this can
simplify your code.
 String
Another composite data type is a string, string can
be treated as a composite data type as they can
breakdown into single characters
 Union
Union is another composite data type it allows
you to store data different types of data in the
same variable. A value can only store one data
at a time. This is useful in situations where you
would like to save memory by storing only the
most important data types.
Operators
An operator is used to perform operations on
values and variables.
Operators contain special symbols
EG (+, -, * etc.)
Operand this is a value which the operator is
applied

Operators Names Examples

+ Addition 10+3

- Subtraction 10-3

* Multiplication 10*3

/ Division 10/3

% Modulus 10%3

** Exponentiation 10**3

// Floor Division 10//3

You might also like