Python operator-How to use an assignment operator instance in combat

Source: Internet
Author: User
In this article, let's talk about the assignment operator in the python operator, and hopefully this article will give you some help in learning about Python.

Assignment operators:

The following assumes that the variable A is 10 and the variable B is 20:

=    Simple assignment operator    C = A + B assigns the result of the operation of A + B to the C + +    assignment operator C + =    A is equivalent to C = c + a    =    subtraction assignment operator    C = A The equivalent of C = c-a    *=    multiplication assignment operator    C *= A is equivalent to C = c * A    /=    division assignment operator    C/= A is equivalent to C = c/a    %=    Fetch The modulo assignment operator    C%= A is equivalent to C = c% A    **=    power assignment operator    C **= A is equivalent to C = c * * A    //=    take the divisible assignment operator    C//= A is equivalent to c = c//A

Some of the commonly used assignment operators are written above, using the assignment operator to illustrate some examples:

#!/usr/bin/python#-*-coding:utf-8-*-a = 21b = 10c = 0 c = a + Bprint "1-c value is:", c c + = Aprint "2-c value is:", c
  
   c *= aprint "3-c value is:", c c  /= a print "4-c value is:", c  C = 2c%= Aprint "5-c value is:", c C **= aprint "6-c The value is: ", c C//= aprint" The value of 7-c is: ", C
  

The answers to the above examples are as follows:

The value of 1-C is: The value of 312-C is: The value of 523-C is: The value of 10924-C is: 525-c value is: 26-c value is: 99864

The assignment operator in the Python operator is not difficult to understand, as long as you try to give some more examples to experiment and believe it will be mastered soon, hopefully this article will help you to learn python.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.