Python- Numeric literals

Good Morning boys.

     I hope your practice sessions for Python are continuing at home. Keep the good work going. Today is the day, don't wait.
    ------------------------------------------------------------------------
    The Google Meet Class link for today's class is:

    Meeting ID

    _____________________________________________________________________________

    By the end of this session, you will be able understand and apply the following concepts:
    • What are variable?
    • Ways of assigning  variables
    • Concepts of multiple assignments
    • Introduction to data types in Python (Just introduction)
    • Numeric data type - types and exact difference       
    _______________________________________________________________________________                                                 

    Answers for the Exercise questions based on Strings given in the previous session are as follows.
    PLEASE CHECK YOUR ANSWERS

    1. Is there a difference between "Geeta" and 'Geeta'? Justify.
    No difference as a string can be either enclosed in a single quotes
    as in 'Geeta' or double quotes as in "Geeta"
    1. Predict the output of the following:
      1. >>> print("SCS"*5) SCSSCSSCSSCSSCS >>> print(("SCS"," ")*5) ('SCS', ' ', 'SCS', ' ', 'SCS', ' ', 'SCS', ' ', 'SCS', ' ') >>> print("I"+"Love"+"Columbas") ILoveColumbas >>> print("I","Love","Columbas") I Love Columbas
    2. Suppose
      str='I LOVE COLUMBAS'
    Predict the output of the following:
    print str          # Prints complete string
    Output: I LOVE COLUMBAS
    print str * 2      # Prints string two times
    Output:I LOVE COLUMBASI LOVE COLUMBAS
    
    print str + " MUSIC"
    I LOVE COLUMBAS Music

    ------------------------------------------------------------------------------------

     PYTHON VARIABLES
    Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
    Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables.

    Assigning Values to Variables

    Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.
    The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. For example −
    (LIVE DEMO- Hyperlink to help you understand the working practically)
    #!/usr/bin/python
    
    counter = 100          # An integer assignment
    miles   = 1000.0       # A floating point
    name    = "John"       # A string
    
    print counter
    print miles
    print name
    Here, 100, 1000.0 and "John" are the values assigned to countermiles, and name variables, respectively. This produces the following result −
    100
    1000.0
    John
    

    Multiple Assignment

    Python allows you to assign a single value to several variables simultaneously. For example −
    a = b = c = 1
    
    Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example −
    a,b,c = 1,2,"john"
    
    Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively, and one string object with the value "john" is assigned to the variable c.
    SO, effectively the above SINGLE statement is assigning three variable a,b,c to the following values :
    a=1
    b=2
    c="john"

    Standard Data Types

    The data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them.
    Python has five standard data types −
    • Numbers
    • String
    • List
    • Tuple
    • Dictionary

    ___________________________________________________

    Python Numbers

    There are three numeric types in Python:
    • int
    • float
    • complex
    Variables of numeric types are created when you assign a value to them:

    Example

    x = 1    # int
    y = 2.8  # float
    z = 1j   # complex
    To verify the type of any object in Python, use the type() function:

    Example

    print(type(x))
    print(type(y))
    print(type(z))
    Try it Yourself »

    Int

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

    Example

    Integers:
    x = 1
    y = 35656222554887711
    z = -3255522

    print(type(x))
    print(type(y))
    print(type(z))
    Try it Yourself »

    Float

    Float, or "floating point number" is a number, positive or negative, containing one or more decimals.

    Example

    Floats:
    x = 1.10
    y = 1.0
    z = -35.59

    print(type(x))
    print(type(y))
    print(type(z))
    Try it Yourself »
    Float can also be scientific numbers with an "e" to indicate the power of 10.

    Example

    Floats:
    x = 35e3
    y = 12E4
    z = -87.7e100

    print(type(x))
    print(type(y))
    print(type(z))
    Try it Yourself »

    Complex

    Complex numbers are written with a "j" as the imaginary part:

    Example

    Complex:
    x = 3+5j
    y = 5j
    z = -5j

    print(type(x))
    print(type(y))
    print(type(z))
    Try it Yourself »

    Type Conversion

    You can convert from one type to another with the int()float(), and complex() methods. This is also known as TYPECASTING.

    Example

    Convert from one type to another:
    x = 1 # int
    y = 2.8 # float
    z = 1j # complex
    #convert from int to float:a = float(x)

    #convert from float to int:b = int(y)

    #convert from int to complex:c = complex(x)

    print(a)
    print(b)
    print(c)

    print(type(a))
    print(type(b))
    print(type(c))
    Try it Yourself »
    Examples
    Here are some examples of numbers −
    intlongfloatcomplex
    1051924361L0.03.14j
    100-0x19323L15.2045.j
    -7860122L-21.99.322e-36j
    0800xDEFABCECBDAECBFBAEl32.3+e18.876j
    -0490535633629843L-90.-.6545+0J
    -0x260-052318172735L-32.54e1003e+26J
    0x69-4721885298529L70.2-E124.53e-7j
    • Python allows you to use a lowercase l with long, but it is recommended that you use only an uppercase L to avoid confusion with the number 1. Python displays long integers with an uppercase L.
    • A complex number consists of an ordered pair of real floating-point numbers denoted by x + yj, where x and y are the real numbers and j is the imaginary unit.
    ----------------------------------------------------------------------------------------------------------------
    EXERCISE
    1. What are variable? Why do we need variables?
    2. What can you say about declaration of variable in Python? Give example.
    3. In the following statements, 
              a=10.0

              b=57

              c="a"

              d="SCS"

              

               a) what is the data type of the variables a,b,c and d ?

               b) what will be the output of the  statements that follow:

                  print(a)

                  print(b)

                  print(c)

                  print(d)        
             4.  What is the purpose of the multiple assignment statements?
              5. What are the numeric data types available? Give example
              6. What is Typecasting? Name the functions used for typecasting.
              7. Give the output of the following set of statements
                   a= 27.325
                   b=int(a)
                   print("b=",b)

    Comments

    1. Good Morning. Pls share your name and roll no and join the Google meet class. link has been given at the top

      ReplyDelete
    2. Good Morning Ma'am
      Kavyansh Bagotra 9D
      Roll No. 6

      ReplyDelete
    3. Good morning ma’am!! Arjav Jain of class 9D here

      ReplyDelete
    4. Good morning ma'am
      My name is soumil arora

      ReplyDelete
    5. Good morning mam I am Gunamay prasad of class 9 D

      ReplyDelete
    6. Good morning ma'am I am vansh bharti of class 9D

      ReplyDelete
    7. Good morning ma’am
      My name is Ryan Rahuel Valentine from class 9-D

      ReplyDelete
    8. Good morning mam I am Arush Jain of class 9th D

      ReplyDelete
    9. Good morning ma'am this side piyushdawla class9D

      ReplyDelete
    10. Good Morning Ma'am I am Hrishit Deb of class 9-D

      ReplyDelete
    11. Good morning ma'am this is Riyan Gabriel from class 9-D

      ReplyDelete
    12. Good morning mam I am Sandarbh of class 9-D

      ReplyDelete
    13. Good morning mam I am Kritik Kuraria

      ReplyDelete
    14. Good morning mami am kenneth barrett of class 9-D

      ReplyDelete
    15. Good morning ma’am I am Aditya Narayan Padhy of class 9D

      ReplyDelete
    16. Good morning ma'am this is Vincent Zacharias

      ReplyDelete
    17. Good morning ma'am.
      My name is Ojas Khanna

      ReplyDelete
    18. Good afternoon ma'am! Ma'am don't we have to follow the syntax print(str) in python as it is mentioned that print str which does not have parentheses
      Regards,
      Arjav Jain

      ReplyDelete
    19. Seeing the blogs after a long time

      ReplyDelete

    Post a Comment

    Popular posts from this blog

    HOLIDA'S HW

    Introduction

    python-PROGRAM(1)