2 Dec 2020

Values and data types

Values :
   
         * Value can be any letter, number or stings. For example ; 2 , 4.56 , "Hello" (these values are belongs to different data types)

Data types :
     
           * Every value in python has data type

            * It is a set of values, and the allowable operations on these values. 
  
             * Python has four standard data types they are :

            

Numbers :

         * This data type stores numeric values and it is immutable ( values/items cannot be changed).

          * There are three different types in numbers :
                     • Integer (int)
           
                     • floating point (float)

                     • Complex number

Integer :

           Integers or int are the whole number. They can be positive or negative but they must be without decimal values .

             Eg : 0 , 28 ,-30 etc. . .

Float :

           A float or floating point number contains only decimal values.

              Eg : 3.14 , - 4.5 etc....

Complex :

          A complex number consist of two parts real and imaginary. The imaginary part written with 'j' suffix.

                Eg : 3+ 5j

Dictionary :
               
             A dictionary is an unordered collection of items. Each item of a dictionary has a key/value pair and they are written within Curley braces { } . We Separate key and values with :

                   Eg : {"year" : 2000}
                               Key.              Value

Boolean :

           Data with one of two build-in values
True or False. 

Note : 'T' (True) and 'F'(False) are must be uppercase letters. 

Sequence :

       A sequence is an ordered collection of similar data types. Python has the following built-in sequence data types.

String :

       A string value is a collection of one or more characters put in single (' '), double(" ")or  triple quotes( "' "').Strings are immutable i.e. the contents of the string cannot be changed after it is created.

          Eg : * 'Good morning'
         
                  * "Hello"
  
                  * "' world is awesome"'

Tuple :

      A tuple object is an ordered collection of one or more data items they are put into the parentheses ( ). A tuple is an immutable list. i.e. once a tuple has been created, you can't add elements to a tuple or remove elements from the tuple. Tuples are faster than lists. If the user wants to protect the data from accidental changes, tuple can be used. Tuples can be used as keys in dictionaries.

              Eg : ( " this is awesome")

List :

           List is an ordered sequence of items. Values in the list are called elements / items. It can be written as a list of comma-separated items (values) between square brackets[ ]. Items in the lists can be of different data types. 

Operations on sequence

              * Indexing
      
              * Slicing

              * Concatenation

              * Repetitions

               * Updation, Insertion, Deletion.

Indexing :
   
             Accessing the position of the items.

                        

                 
           Positive indexing helps in accessing the string from the beginning and Negative subscript helps in accessing the string from the end. Subscript 0 or negative n (where n is length of the string) displays the first element.Example: A[0] or A[-5] will display “H”.

Slicing :

          Slicing means taking elements from one given index to another one. we pass slice instead of index [start:end]. we can also define as[start:end:step].

Concatenation :

               Merge one string into another one. for example, a = 'hello' and b = 'world' c = a+b.
 
                                           

Repetition:
      
                          Repetition is used to repeat the string in the program for certain lengths, It is denoted by the symbol  ' * ' .

Example :
a = " happy forever"
print (a*2);

output:
     "happy forever happy forever" 

Updation : Updating the list using index value.

Insertion : Insert an elements in needed position.

Deletion : Remove an element which is not needed.                                                          

No comments:

Post a Comment

Operator precedence

           When an expression contains more than one operator, the order of evaluation depends on the order of operations.            The ac...