9/22/22

Arrays in Python

 Python Notes Unit 1, Part 3

UNIT – 1 (part 3)

    



Introduction to Python Part 1

                    Introduction to Python Part 2


Introduction to Python

History and its Features

Basic Syntax

Understanding Python variables

Numeric data types

Using string data type and string operations

Basic Operators

Understanding coding blocks.

Defining list and list slicing,

Other Data Types- Tuples. List, Python Dictionary, Arrays, Associative Arrays/Hashes


 ARRAY IN PYTHON

    1.   An array is a collection of common type of data structures having elements with same data type.

    2.   Array is mainly used to store collections of data.

    3.   Arrays are handled by the “array” module. If you can create array using array module, elements of the array must be of the same numeric type.

    4.   The Arrays are especially useful when you have to processed the data dynamically.

    5.   Python arrays are used when you need to use many variables which are of the same type.

 

Syntax for create an Array in Python –

                     You can declare an array in Python while initializing it using the following syntax.

                              arrayName = array.array(data Type, [array items])

                     

In python, there are following operation can be performed on array –

 

BASIC ARRAY OPERATIONS                             

(a)     Adding/changing

(b)     Removing/deleting

(c)      Searching

(d)     Slicing

(e)      Looping

                                                             

 

Associative Array –

    1.   Associate array are also called maps or symbol tables or dictionaries.

    2.   In an associative array, the values of the array are key-value pairs.

    3.   The key represents a lookup value or an index. The value is the value stored for that key.

    4.   Each key must be unique.

    5.   The Associative Array data structure is an abstract data structure.

    6.   There are several ways to implementing it, with the hash table being the most common.

 

Hash Table –

    1.   A hash table has two parts: An array and a hash function.

    2.   The hash function is a function that returns an integer given a key.

    3.   The hash function is used to determine where the value should be stored.

    4.   The name of the key is used to access its associated value.

    5.   This makes searching for values in a hash table very fast, irrespective of the number of items in the hash table.

  The hash table data structure stores elements in key-value pairs where

(a)         Key – unique integer that is used for indexing the values

(b)         Value – data that are associated with keys. 


Basic operators in Python   

Operator –

Operator is a symbols which tells the interpreter to do a specific operation such as arithmetic, comparison, logical and so on.

In Python, there are following types of Operators-

1.   Arithmetic Operator

2.   Relational Operator

3.   Bitwise Operator

4.   Assignment Operator

5.   Logical Operator 

 

Arithmetic Operator – 

An Arithmetic operator takes two operands as input, for perform a calculation and returns the result.

For Example- 

              a= 2+3   

Here 2 and 3 are the operands and + is the Arithmetic operator.

The result of the operation is stored in the variable a.

 

Relational Operator-

A Relational Operator is used to comparing two operands to decide a relation between them. Its returns a Boolean value based on the condition. 

For Example-

                   8>3 return true.

Here 8 and 3 are operands and > is operator.

Bitwise Operator-

A bitwise operator performs operation on the operand bit by bit. There          are mainly 4 types of bitwise operator is used –

1.   Bitwise AND (&)

2.   Bitwise OR (|)

3.   Bitwise XOR (^)

4.   Bitwise NOT (~)

Consider a = 2 (10)2 and b = 3 (11)2

Perform bitwise AND operation on the operands-

          a & b = 2 (10&11 = 10)2

Perform bitwise OR operation –

         a | b = 3 (10|11 = 11)2 

Perform bitwise XOR operation-

        a ^ b = 1 (10^11=01)2

   Perform bitwise NOT operation

      ~a = -3 ((00000010) = (11111101))2

Assignment Operator –

An Assignment operator is used to assign a value to a variable.

This is usually combined with other operators where the operation is performed on the operands and the result is assigned to the left side operands.

For Example- 

                a = 9

Here “=” is an assignment operator, and the result is stored in variable a.

 

Logical Operator-

A logical operator is used to make a decision based on one or more conditions. The logical operators used in Python are -

1.   and

2.   or

3.   not   

For example –

        a and b

        a or b

         not a

 

 

************************* THE END *************************


Introduction to Python Part 1

                    Introduction to Python Part 2


Unit 2 Notes will uploaded ASAP keep studying.











No comments:

Post a Comment

Please do not enter any spam link in the comment box and use English and Hindi language for comment.

Latest Update

Conditional Statements in Python

Popular Posts