NUMBERS



Python - NUMBERS


Number data types store numeric values.There are three numeric types in Python :


  • int

  • float

  • complex


    Number objects are created when you assign a value to them. For example −


    Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    
    (Number objects are created by assigning values to them and further performs required calculations as follows)
    >>> var_x=1 (int)
    >>> var_x
    1
    >>> var1=25
    >>> var1
    25
    >>> var=2
    >>> var
    2
    >>> x=1
    >>> x
    1
    >>> y=2.5 (float)
    >>> y
    2.5
    >>> z='freedom' (string)
    >>> z
    'freedom'
    >>> x+y (operation based on assigned values)
    3.5
    >>> z=1j (complex)
    >>> z
    1j
    

    Type Conversion:

    You can convert from one type to another with the int(), float(), and complex() methods :


    >>> y=2.5
    >>> x=int(y) (conversion of float to integer)
    >>> x = int(2.5)
    >>> print (x)
    2
    >>> x=1
    >>> y=float(x) (conversion of integer to float)
    >>> print(y)
    1.0
    >>> x=1
    >>> z=complex(x) (conversion of int to complex)
    >>> print(z)
    (1+0j)
    
    

    Random Number :

    Python does not have a random() function to make a random number, but Python has a built-in module called random that can be used to make random numbers.


    Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    
    >>> import random
    >>> print(random.randrange(1,10))
    6
    >>> import random
    >>> print(random.randrange(1,6))
    1
    
    


    RegEx SETS

    Python - RegEx SETS

    posted on 2019-11-12 23:06:24 - Python Tutorials


    RegEx_Functions

    Python - RegEx_Functions

    posted on 2019-11-09 06:07:29 - Python Tutorials


    RegEx_Sets

    Python - RegEx_Sets

    posted on 2019-11-09 05:30:54 - Python Tutorials


    Prompt Examples

    ChatGPT Prompt Examples

    posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


    Use Cases

    Chat GPT Key Use Cases

    posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


    Prompt Frameworks

    Prompt Frameworks

    posted on 2023-06-21 19:33:06 - ChatGPT Tutorials