Python For Beginner's Day - 9

·

3 min read

Escape Characters:

  • It is represented by backslash(\) followed by the character to insert.

  • To insert a string with double quotes inside the string then usually we get an error, to overcome that this escape character is used like \"

Escape characterUse
\nThe new line character helps to insert a new line before or after a string.
\\The backslash character allows the programmer to insert a backslash to the output.
\'The single quote character will add single quote to the string.
\tIt represents tab/space between the strings.
\bThis provides backspace to the string. It is inserted by adding a backslash followed by “b”.

“b” here represents backslash. |

Python Operators:

  • used to perform operations on variables and values.

  • Arithmetic Operators:

    • used to perform mathematical operations.

      | Operator | Name | Example | | --- | --- | --- | | + | Addition | x + y(performs addition between 2 numeric values) | | - | Subtraction | x - y(performs subtraction between 2 numeric values) | | * | Multiplication | x * y(perform multiplication between 2 numeric values) | | / | Division | x / y(perform division between 2 numeric values | | % | Modulus | x % y(performs division but the result which it returns is the remainder) | | ** | Exponentiation | x ** y(it represents x to the power of y) | | // | Floor division | x // y(performs division but the result which it returns is the nearest whole number) |

    • Comparison Operator:

      • used to compare 2 values.

        | Operator | Name | Example | | --- | --- | --- | | \== | Equal | x == y(returns true if both values are equal) | | != | Not equal | x != y(returns true if both values are not equal) | | \> | Greater than | x > y(returns true if x is greater than y) | | < | Less than | x < y(returns true if x is less than y) | | \>= | Greater than or equal to | x >= y(returns true if x is greater than or equal to y) | | <= | Less than or equal to | x <= y(returns true if x is less than or equal to y) |

    • Assignment Operator:

      • used to assign values to the variables.

        | Operator | Example | | --- | --- | | \= | x = 5(assigns value 5 to x) | | += | x += 4( same as x = x + 4) | | -= | x -= 4(same as x = x - 4) | | *= | x *= 4(same as x = x*4) | | /= | x /= 4(same as x = x/4) | | %= | x %= 4(same as x = x%4) | | //= | x //= 4(same as x = x//4 which does division and returns nearest whole number) | | **= | x **\= 4( same as x = x ** 4 which does x to the power of 4) |

        - to be contd.....