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

2 - Data Types

data type in python

Uploaded by

hamoelsyed2005
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)
4 views

2 - Data Types

data type in python

Uploaded by

hamoelsyed2005
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
You are on page 1/ 6

Concept of variables

Variables are locations that are temporarily reserved in memory for the
purpose of storing data while the program is running.

In python, the programmer is not responsible for defining the types of


variables; they ate automatically assigned based on the types of
values assigned to them at runtime

Define new variable


In python, you can’t declare a variable without assigning a value to it when
you declare it.

Defining multiple variables


With same value:

With different values:


Knowing the type of variable
To find out the type of any variable you can use the function type ().

Remember that the type of variable in python isn’t fixed because it


changes automatically depending on the type of value stored in it.
Types of variables in Python:

➢ Lists [ ]: Arrays that don’t have a fixed size.


➢ Tuples ( ): Arrays whose size and values are fixed and can’t be
changed.
➢ Sets { }: Arrays that don’t have a fixed size, and their values can’t be
deleted, and new values can be added to them.
➢ Dictionaries {key : value}: tables that store data using keys
and values.
List [ ]:
Array that doesn’t have a fixed size and it can store any data type:

Accessing in list any list counting from 0 to ..

Add Elements in this list


Add in the end

Add in any index you want


Tuples ( ):
is an array of fixed size and immutable values that can store values of
different types at the same time

Accessing in list any tuple counting from 0 to ..

Immutable values

Knowing the index of specific elements


Set { }:
an array that has no fixed size and its values are immutable and can store
values of different types at the same time.
In this type of arrays, the data is stored randomly and not in the order in which
they were entered, and the reason is that a number is not given. Index Specific
to each item. This is also why you cannot access a specific item. In Set
Directly because his index doesn't have a number.

Doesn’t repeat any same value

Dictionaries {key: value}


The idea of gender Dictionary It is to put a key for each value, then you reach
the value of each existing element through its private key.
You can imagine that dictionary is a table in which data is stored using keys
and values.
Key1 Value1
Key2 Value2
You are free to store keys and values of any type you want.

1 Hi
2 Bye
3 Mrs
4 ms

You might also like