ACHIEVEMENTS

We help our clients integrate, analyze, and use their data to improve their business.

36

GREAT POST

300

HAPPY CLIENTS

650

COFFEES DRUNK

2000

PAGE VIEW

Showing posts with label Python - Basic Syntax. Show all posts
Showing posts with label Python - Basic Syntax. Show all posts
  • Python - Basic Syntax

    Basic Operators


    Operators are the builds which can control the value of operands.

    Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called Operator.

    Sorts of Administrator

    Python dialect underpins the accompanying sorts of operators.

     Arithmetic Operators
     Comparison (Relational) Operators
     Assignment Operators
     Logical Operators
     Bitwise Operators
     Membership Operators
     Identity Operators

    Let us have a look on all operators one by one.

    Python Arithmetic Operators


    Assume variable a holds 10 and variable b holds 20, then −
    Operator
    Description
    Example
    + Addition
    Adds values on either side of the operator.
    a + b = 30
    - Subtraction
    Subtracts right hand operand from left hand operand.
    a – b = -10
    * Multiplication
    Multiplies values on either side of the operator
    a * b = 200
    / Division
    Divides left hand operand by right hand operand
    b / a = 2
    % Modulus
    Divides left hand operand by right hand operand and returns remainder
    b % a = 0
    ** Exponent
    Performs exponential (power) calculation on operators
    a**b =10 to the power 20
    //
    Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity):
    9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0


    Python Comparison Operators


    These operators think about the values on either sides of them and choose the relation among them. They are likewise called Relational operators.

    Expect variable a holds 10 and variable b holds 20, then −

    Operator
    Description
    Example
    ==
    If the values of two operands are equal, then the condition becomes true.
    (a == b) is not true.
    !=
    If values of two operands are not equal, then condition becomes true.

    <> 
    If values of two operands are not equal, then condition becomes true.
    (a <> b) is true. This is similar to!= operator.
    > 
    If the value of left operand is greater than the value of right operand, then condition becomes true.
    (a > b) is not true.
    < 
    If the value of left operand is less than the value of right operand, then condition becomes true.
    (a < b) is true.
    >=
    If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.
    (a >= b) is not true.
    <=
    If the value of left operand is less than or equal to the value of right operand, then condition becomes true.
    (a <= b) is true.

    Python Assignment Operators


    Accept variable a holds 10 and variable b holds 20, then –

    Operator
    Description
    Example
    =
    Assigns values from right side operands to left side operand
    c = a + b assigns value of a + b into c
    += Add AND
    It adds right operand to the left operand and assign the result to left operand
    c += a is equivalent to c = c + a
    -= Subtract AND
    It subtracts right operand from the left operand and assign the result to left operand
    c -= a is equivalent to c = c - a
    *= Multiply AND
    It multiplies right operand with the left operand and assign the result to left operand
    c *= a is equivalent to c = c * a
    /= Divide AND
    It divides left operand with the right operand and assign the result to left operand
    c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a
    %= Modulus AND
    It takes modulus using two operands and assign the result to left operand
    c %= a is equivalent to c = c % a
    **= Exponent AND
    Performs exponential (power) calculation on operators and assign value to the left operand
    c **= a is equivalent to c = c ** a
    //= Floor Division
    It performs floor division on operators and assign value to the left operand
    c //= a is equivalent to c = c // a

     

    Python Bitwise Operators


    Bitwise operator works on bits and performs bit by bit operation. Expect if a = 60; and b = 13; Now in twofold organization they will be as per the following −

    a = 0011 1100

    b = 0000 1101

    - -

    a&b = 0000 1100

    a|b = 0011 1101

    a^b = 0011 0001

    ~a = 1100 0011

    There are following Bitwise operators upheld by Python language

    Operator
    Description
    Example
    & Binary AND
    Operator copies a bit to the result if it exists in both operands
    (a & b) (means 0000 1100)
    | Binary OR
    It copies a bit if it exists in either operand.
    (a | b) = 61 (means 0011 1101)
    ^ Binary XOR
    It copies the bit if it is set in one operand but not both.
    (a ^ b) = 49 (means 0011 0001)
    ~ Binary Ones Complement
    It is unary and has the effect of 'flipping' bits.
    (~a ) = -61 (means 1100 0011 in 2's complement form due to a signed binary number.
    << Binary Left Shift
    The left operands value is moved left by the number of bits specified by the right operand.
    a << = 240 (means 1111 0000)
    >> Binary Right Shift
    The left operands value is moved right by the number of bits specified by the right operand.
    a >> = 15 (means 0000 1111)

    Python Logical Operators


    There are following Logical operators supported by Python language. Assume variable a holds 10 and variable b holds 20 then

    Used to turn around the sensible condition of its operand.
    Operator
    Description
    Example
    and Logical AND
    If both the operands are true then condition becomes true.
    (a and b) is true.
    or Logical OR
    If any of the two operands are non-zero then condition becomes true.
    (a or b) is true.
    not Logical NOT
    Used to reverse the logical state of its operand.
    Not(a and b) is false


    Python Membership Operators

    Python’s membership operators test for membership in a sequence, such as strings, lists, or tuples. There are two membership operators as explained below

    Operator
    Description
    Example
    in
    Evaluates to true if it finds a variable in the specified sequence and false otherwise.
    x in y, here in results in a 1 if x is a member of sequence y.
    not in
    Evaluates to true if it does not finds a variable in the specified sequence and false otherwise.
    x not in y, here not in results in a 1 if x is not a member of sequence y.

    Python Identity Operators

    Operator
    Description
    Example
    is
    Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
    x is y, here is results in 1 if id(x) equals id(y).
    is not
    Evaluates to false if the variables on either side of the operator point to the same object and true otherwise.
    x is not y, here is not results in 1 if id(x) is not equal to id(y).


    Python Operators Precedence


    The following table lists all operators from highest precedence to lowest.
    Operator
    Description
    **
    Exponentiation (raise to the power)
    ~ + -
    Complement, unary plus and minus (method names for the last two are +@ and -@)
    * / % //
    Multiply, divide, modulo and floor division
    + -
    Addition and subtraction
    >> <<
    Right and left bitwise shift
    &
    Bitwise 'AND'
    ^ |
    Bitwise exclusive `OR' and regular `OR'
    <= < > >=
    Comparison operators
    <> == !=
    Equality operators
    = %= /= //= -= += *= **=
    Assignment operators
    is is not
    Identity operators
    in not in
    Membership operators
    not or and
    Logical operators


  • Installing Python

    Introducing Python 


    Each stage (mix of PC equipment and working framework programming) has uncommon guidelines that it takes after when running applications. The Python application conceals these subtle elements from you. You write code that keeps running on any stage that Python bolsters, and the Python applications make an interpretation of that code into something the stage can get it. In any case, all together for the interpretation to happen, you should have a rendition of Python that deals with your specific stage. 


    To get the correct rendition for your stage, you have to go to http://www.python.org/download/discharges the download segment is at first escaped see, so you have to scroll mostly down the page. The primary part of the page contains joins for Windows, Macintosh OS X, and Linux downloads. The stage particular connections on the left half of the page demonstrate you elective Python designs that you can utilize when the need emerges. For instance, you might need to utilize a more propelled editorial manager than the one gave the default Python bundle, and these option setups can give one to you. 


    you need to work with another stage ??, tap the Other connection on the left half of the page. You see a rundown of Python establishments for different stages. A significant number of these establishments are kept up by volunteers instead of by the general population who make the adaptations of Python for Windows, Macintosh OS X, and Linux. 




    Installing Python
    After you download your copy of Python, it’s time to install it on your system. The downloaded file contains everything needed to get you started:
    ✓ Python interpreter
    ✓ Help files (documentation)
    ✓ Command-line access
    ✓ Integrated DeveLopment Environment (IDLE) application
    ✓ Uninstaller (only on platforms that require it)



    Introducing Python 

    After you download your duplicate of Python, it's a great opportunity to introduce it on your framework. The downloaded document contains everything expected to kick you off: 


    ✓ Python translator 


    ✓ Help records (documentation) 


    ✓ Summon line get to 


    ✓ Coordinated Advancement Environment (Sit out of gear) application 


    ✓ Uninstaller (just on stages that require it) 


    Working with Windows 


    The establishment procedure on a Windows framework takes after a similar methodology that you use for other application sorts. The primary distinction is in finding the record you downloaded so you can start the establishment procedure. The accompanying strategy ought to work fine on any Windows framework, whether you utilize the 32-bit or the 64-bit adaptation of Python. 


    1. Find the downloaded duplicate of Python on your framework. 


    The name of this record fluctuates, yet regularly it shows up as python-3.3.4.msi for 32-bit frameworks and python-3.3.4.amd64.msi for 64-bit frameworks or any variant you have downloaded. The rendition number is inserted as a major aspect of the filename. For this situation, the filename alludes to rendition 3.3.4. 


    2. Double tap the establishment record. 


    (You may see an Open Record – Security Cautioning discourse box that requests that whether you need run this document. Click Run on the off chance that you see this discourse put away pop.). The correct exchange box you see relies on upon which variant of the Python establishment program you download. 




    3. Pick a client establishment alternative (utilize the default setting of Introduce for All Clients) and snap Next. 

    Introduce solicits you to give the name from an establishment index for Python. Utilizing the default goal will spare you time and exertion later. Notwithstanding, you can introduce Python anyplace you want. 





    Utilizing the Windows \Program Records or \Program Documents (x86) envelope is risky for two reasons. To begin with, the envelope name has a space in it, which makes it difficult to access from inside the application. Second, 

    the envelope for the most part requires overseer get to, so you'll always fight the Client Account Control (UAC) highlight of Windows on the off chance that you introduce Python in either organizer. 



    4. Sort a goal envelope name, if vital, and click Next. 

    Python requests that you alter its establishment. Empowering the Add python.exe to Way choice will spare you time later. This element makes it conceivable to get to Python from the Charge Provoke window. Try not to stress a lot over how you utilize this component just yet, yet it truly is a decent element to have introduced. 




    5. (Discretionary) Tap the down bolt alongside the Add python.exe to Way choice and pick the Will Be Introduced On Neighborhood Drive choice. 

    6. Click Next. 

    You see the establishment procedure begin. Sooner or later, you may see a Client Account Control discourse box requesting that whether you need play out the introduce. On the off chance that you see this exchange box, click Yes. The establishment proceeds and you see an Establishment Finish discourse box. 

    7. Click Wrap up. 


    VOILÀ!! 

    Python is prepared for utilize. 


    Working with the Macintosh 

    Your Macintosh framework likely as of now has Python introduced on it. In any case, this establishment is typically a couple of years old — or whatever the age of your framework happens to be. 


    The Panther adaptation of OS X (10.5) utilizes a truly old variant of Python 2.5.1. This specific form needs guide access to the Sit still application. Accordingly, you may find that some post practices won't work legitimately. The most current form of OS X at the season of this composition (Free thinkers, or 10.9) accompanies Python 2.7, which is okay to work through the cases in the post. Contingent upon how you utilize Python, you might need to overhaul your establishment sooner or later. Some portion of this procedure includes introducing the GNU Compiler Accumulation (GCC) apparatuses with the goal that Python has admittance to the low-level assets it needs. The accompanying strides kick you off with introducing another rendition of Python on your Macintosh OS X framework. 


    1. Explore to http://www.python.org/download/discharges/3.3.4/ 


    with your program. 


    You see data with respect to the most recent form of Python 


    2. Tap the fitting connection for your rendition of OS X: 


    a. Python 3.3.4 Macintosh OS X 64-bit/32-bit x86-64/i386 Installer for 32-bit or 64-bit forms on the Intel processor 


    b. Python 3.3.4 Macintosh OS X 32-bit i386/PPC Installer for 32-bit forms on the Power PC processor 


    The Python plate picture starts downloading. 


    Be quiet: 


    The plate picture requires a few minutes to download. Most programs give a technique to checking the download procedure with the goal that you can without much of a stretch perceive to what extent the download will take. At the point when the download is finished, your Macintosh consequently opens the plate picture for you. The circle picture really resembles an organizer. Inside this organizer, you see various records, including python.mpkg. The python.mpkg document is the one that contains the Python application. The content documents contain data about the assemble, permitting, and any late-breaking notes. 


    3. Double tap python.mpkg. 


    You see an Appreciated discourse box that enlightens you regarding this specific Python fabricate. 


    4. Click Proceed with three circumstances. 


    The establishment program shows late-breaking notes about Python, authorizing data (click Concur when gotten some information about the permitting data), and, at long last, a goal exchange box. 


    5.Installing Python and snap Proceed. 


    The Establishment Sort discourse box shows up. This discourse box performs two assignments: 


    • Click Tweak to change the list of capabilities that is introduced on your framework. 


    • Click Change Introduce Area to alter where the installer places Python. 


    The post expect that you're playing out a standard establishment and that you haven't changed the establishment area. In any case, these choices are accessible on the off chance that you need to utilize them. 


    6. Click Introduce. 


    The installer may ask for your director secret key. Sort the director name and secret word, if required, into the discourse box and snap alright. You see an Introducing Python exchange box. The substance of this discourse box will change as the establishment procedure continues so you recognize what a portion of Python the installer is working with. After the establishment is finished, you see an Introduce Succeeded discourse box. 


    7. Click Close. 


    Python is prepared to utilize. (You can close the circle picture now and 


    expel it from your framework.) 


    Working with Linux 


    A few renditions of Linux accompany Python introduced. For instance, in the event that you have a Red Cap Bundle Chief (RPM)- based circulation, (for example, SUSE, Red Cap, Yellow Canine, Fedora Center, and CentOS), you likely as of now have Python on your framework and don't have to do whatever else. Contingent upon which rendition of Linux you utilize, the adaptation of Python changes and a few frameworks do exclude the Intelligent Improvement Environment (Sit without moving) application. On the off chance that you have a more established rendition of Python (2.5.1 or prior), 


    you might need to introduce a more current form with the goal that you have entry to Sit out of gear. 


    You really have two procedures to use to introduce Python on Linux. The accompanying areas examine both methods. The main procedure chips away at any Linux dissemination; the second system has unique criteria that you should meet. 


    Utilizing the standard Linux establishment 


    The standard Linux establishment takes a shot at any framework. Be that as it may, it obliges you to work at the Terminal and sort charges to finish it. A portion of the genuine orders may differ by form of Linux. The data at http://docs.python.org/3/introduce/gives some accommodating tips that you can use notwithstanding the methodology that takes after. 


    1. Explore to http://www.python.org/download/discharges/3.3.4/with your program. 


    You see data with respect to the most recent form of Python 


    2. Tap the proper connection for your form of Linux: 


    a. Python 3.3.4 packed source tarball (any adaptation of Linux) 


    b. Python 3.3.4 xzipped source tarball (better pressure and speedier download) 


    3. At the point when requested that whether you need open or spare the document, pick Spare. 


    The Python source records start downloading. Be understanding: The source records require a moment or two to download. 


    4. Double tap the downloaded record. 


    The Document Director window opens. After the records are extricated, you see the Python 3.3.4 envelope in the Document Supervisor window. 


    5. Double tap the Python 3.3.4 organizer. 


    The Document Administrator extricates the records to the Python 3.3.4 subfolder of your home organizer. 


    6. Open a duplicate of Terminal. 


    The Terminal window shows up. On the off chance that you have never manufactured any product on your framework some time recently, you should introduce the construct basics, SQLite, and bzip2 or the Python establishment will fall flat. Else, you can skip to Step 10 to start working with Python promptly.
  • Powered by Blogger.

    Tags

    Popular Posts