• Types of Operator
  • Bitwise Operators
  • Chapter 4: Python Programming – Basic




    Download 337.24 Kb.
    Pdf ko'rish
    bet5/10
    Sana12.05.2023
    Hajmi337.24 Kb.
    #58921
    1   2   3   4   5   6   7   8   9   10
    Bog'liq
    Patterson C. - Python Learn the Basics FAST From Python Programming Experts
    10 nazorat, Axrorova K. F8
    Chapter 4: Python Programming – Basic
    Operators
    An “operator” is defined as the element that can modify an operand’s value. In this
    example: 3 + 6 = 9, the operands are 3 and 6 while the + symbol is called the operator.
    This chapter will focus on the fundamental operators used in the Python programming
    language.
    Types of Operator
    Python currently supports these types of operators:
    Bitwise Operators
    Identity Operators
    Arithmetic Operators
    Logical Operators
    Membership Operators
    Relational or Comparison Operators
    Assignment Operators
    We will now discuss each operators:
    Bitwise Operators
    These operators execute bit by bit operation. If we will assume that x has a value of 60 and
    y has a value of 13, we will have these binary information:
    X = 0011 1100
    Y= 0000 1101


    X and Y = 0000 1100
    X | Y = 0011 1101
    ~ X = 1100 0011
    X * Y = 0011 0001
    We will now use these binary data to show the Bitwise operations used in the Python
    programming language.
    Operators
    Definition
    Examples
    >> Binary Right Shift
    The value of the left operand is moved to the right based on
    the number of bits determined by operand on the right.
    X >> = 15 (which is 0000 1111)
    << Binary Left Shift
    The value of the left operand is moved to the left based on
    the number identified by the operand on the right.
    X << 240 (which is 1111 0000)
    & Binary AND
    This operator copies and pastes a bit to the end result if it is
    present in both operands.
    (X and Y) which is 0000 1100)
    ^ Binary XOR
    This operator duplicates a bit if it is present in one operand
    but not on the other
    (X ^ Y) = 49 (which is 0011 0001)
    ~ Complement of Binary Ones
    This operator is unary and it can flip bits.
    (~ X) = 61 (which is 1100 0011 in complement
    of 2’s form because of a marked binary digit)
    | Binary OR
    This operator duplicates a bit if it is present in one of the
    operands.
    (X | Y) 61 (which is 0011 1101)

    Download 337.24 Kb.
    1   2   3   4   5   6   7   8   9   10




    Download 337.24 Kb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Chapter 4: Python Programming – Basic

    Download 337.24 Kb.
    Pdf ko'rish