Python learning: Commenting, getting user input, string concatenation, operators, expressions

Source: Internet
Author: User
Tags arithmetic arithmetic operators

Comments

#为单行注释
' Three single quotation marks (or "" "three double quotes) for multiple lines of comment, e.g. ' ' annotated content '

Get user input

Input ()

All data that input accepts is a string, even if you enter a number, but it is still treated as a string.
Convert data into strings with STR (transferred data); Convert string to data with int (string to be transferred).

string concatenation

"ABC" + "def" = "abcdef" "abc", "Def" = "adb def"

Operator

1. Arithmetic operators: 5//2=2 (divisible operations), 5/2=2.5;9%2=1 (division takes remainder), 2**10=1024 (exponential operation), +;-;*;/

In Python, the difference in arithmetic operations takes precedence only when the parentheses have no other parentheses.

2. Comparison operator: = = (compare size, equals);! = (comparison size, not equal); >= (compare size, greater than or equal); <= (less than equals)

3. Assignment Operator: = (Assignment), + = (for example: num+=1 equivalent to num=num+1),-= (for example: num-=1 equivalent to Num=num-1), *= (for example: num*=2 equivalent to num=num*2),/= (for example: num/=2 equivalent to num =NUM/2), similar to "//=", "%=", "**="

4. Logical operator: Not;and;or

Ture and false = False;ture and ture = ture;false and ture = False;false and false = False

Ture or false = Ture;ture or ture = Ture;false or ture = False;false or false = False

Not ture = false;not false = Ture

 Logic operator Short Circuit principle:

For and, if the previous condition is false, then the expression of the two conditions of the and before and after the calculation result must be false, the second and subsequent conditions will not be computed;
For or, if the previous condition is true, then the expression of the two-conditional-or-before-or-after condition must be true, and the second and subsequent conditions will not be computed.
Note: The logical operator has no precedence.

An expression

Operator plus operand

Example: 1+2*3

You can assign a value to a variable

Example: net=1+2*3

Python learning: Commenting, getting user input, string concatenation, operators, expressions

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.