eLearning

We are a professional site that will give you the strongest methods to get learn and we will teach you everything about programming and technology

PYTHON

Breaking News

PYTHON
PYTHON
جاري التحميل ...

(Tuple) array in a python Lesson 9:

Storing data in Tuple inside python



And the Tuple is an array of values ​​that are immutable and fixed in size, and it can store values ​​of different types at the same time.

 In the python environment, we use the symbol () to define a single array whose values ​​are fixed and whose size is fixed (and a unary matrix is ​​a one-dimensional array)

We will now create a program or an example to get to know the Tuple array and the method for storing the data inside it. This program or this example will be composed of five code, each code carries a different value for the array

X = ()

In the previous code, we defined an empty array


Z = (1, 2, 3, 4, 5)

Here we define an array that contains only integers


Y = ('Ibrahim', 'john', 'ettore')

 Here we define an array that contains only strings


M = (11, 'twelve', 'Thirteen', Fourteen)

Here we define an array that contains texts and also contains integers


Now, in the following program or the following example, we will define only one array of five fixed elements, and then we will display its values ​​and also display the number of elements it contains

languages ​​= ('French', 'Arabic', 'German', 'English', 'Turkish')

In the previous code, we defined an array that has no specific type and consists of 5 elements

print ('languages:', languages)

And in this code, we are printing the values ​​that the array holds

print ('Number of languages ​​is:', len (languages))

In the previous code, we printed and displayed the number of elements contained in the array

When you run the previous program, you should get the following result

languages ​​:( 'French', 'Arabic', 'German', 'English', 'Turkish')

And in this line the values ​​for the array that we created are already displayed

The number of languages ​​is: 5

Here, too, the number of values ​​contained in the array was displayed without any errors

As for the array, Set

It is a matrix of its values ​​which does not accept change and it has no fixed size and it can store different values ​​at the same time

In the Python programming language environment, we use the symbol {} to define a single array whose values ​​are immutable and the size is not fixed (a unary array is a one-dimensional array)

And the data is stored randomly in the matrices of the set and not in the order, i.e. not in the order in which they were entered into the matrix, and this is due to the fact that this type of matrix does not assign a special index number for each element.

For this reason, also, it is not possible to access a specific element in the Set arrays directly because it originally does not have the Index number, it is the directory that the program or computer uses to find the desired item and with the absence of this evidence, the program or computer cannot determine the desired element

And now we learn together how to store data in Set within the Python environment

X = {}

In this code, we have defined an empty array


Y = {1, 2, 3, 4, 5}

Here, we define an array that contains only integers


Z = {'Mark', 'Marco', 'Joe,' Ronaldo '}

Here, we define an array that contains only strings


M = {11, 'twelve', 'Thirteen', 14, 'fifteen'}

Here we define another array that contains integer text and numbers

In this program or example, we learned together about the method of storing data using the matrix, where we created and defined five different matrices between an empty matrix, a matrix that carries only integer numbers, a matrix that carries text, and an array that carries texts and integers.

We will now illustrate an example close to it, but with the implementation of the orders displaying values ​​and also displaying the number of elements of the matrix

languages ​​= ('French', 'Arabic', 'German', 'English', 'Turkish')

In the previous code, we defined an array that has no specific type and consists of 5 elements

print ('languages:', languages)

And in this code, we are printing the values ​​that the array holds

print ('Number of languages ​​is:', len (languages))

In the previous code, we printed and displayed the number of elements contained in the array


When you run the previous program, you should get the following result :

languages ​​:( 'French', 'Arabic', 'German', 'English', 'Turkish')

And in this line, the values ​​for the array that we created are already displayed

The number of languages ​​is: 5

Here, too, the number of values ​​contained in the array was displayed without any errors

عن الكاتب

ADMIN

التعليقات


اتصل بنا

If you like the content of our blog, we hope to stay in constant contact, just enter your email to subscribe to the blog express mail so that you will receive the new blog first-hand, and you can send a message by clicking the next button ...

جميع الحقوق محفوظة

eLearning