Operators: ========== Tokens: ======== ==> 5-different types of tokens in any language to write/understand programs 1) Keywords 2) Identifiers 3) Datatypes Pre-defined : int, float, complex, bool 4) Operators 5) Strings Operand ======= 123 + 121 a = 12 b = 21 c = a + b ==> a data/value/variable on which we can define an operation is called an "Operand". Operator: ======== ==> a symbol which denote an operation ex: + ==> sum/addition Expression ========== combination of operands with operator is called as an "Expression" Ex: c = a + b here: c, a, b ==> operands +, = ==> Operators = ==> Assignment Statement ========= The line of program is called a statement. a = 12 b = 13 f = a g = h c = a-b d = a+b e = a * b print(c) print(d) print(e) Note: ==== In Java/C/C++ ==> statements should terminate with semicolon (;). But, In Python the statement may or may not be end with semicolon. ==> The expression within the program terminate in a line act as a statement but the statement Should not be an expression. Types of Operators =================== Three types: 1) Unary Operators 2) Binary Operators 3) Ternary Operators ==> Unary Operator can always define with single operand. Ex: not True ==> False not False ==> True -7 ==> Unary minus defined to 7 for changing the sign from plus to minus. ==> Binary Operator can always define with two operands. Ex: 12 < 13 12 == 12 ==> Ternary Operator can define with more than two operands Ex: Conditional Operator Syntax: result = test-condition if value1 else value2 We have: 1) Arithmetic Operators 2) Assignment Operator 3) Relational Operators 4) Logical Operators 5) Bitwise Operators 6) Conditional Operators 7) Special Operators 1) Arithmetic Operators ======================== a = 10 b = 11 # +, -, *, /, //, %, ** print("The Sum = ",a+b) print("The Difference = ",a-b) print("The Product = ",a*b) # / ==> normal division operator can return a quotient value in floating-point format. print("The Quotient = ",b/a) # // ==> floor division operator can return a quotient value in integral format. print("The Quotient = ",b//a) # % ==> Modulo division operator can return a remainder print("The Remainder = ",b%a) # ** ==> Exponent Operator/Power Operator # 2 ^ 5 = 32 print("The Power = ",2**5) ============================================ 2) Assignment Operator ======================= # = # to assign the value to the variable # or to assign the expression to the variable # or to assign a value to the expression we can use "assignment operator". a = 12 b = a - 1 # usually, the assignment operator can work from right to left print(a) print(b) # Compound Operator # +=, -=, *=, /=, //=,%=, **= # a = a + b a += b # a = a + b print(a) print(b) # a = a - b a -= b # a = a - b print(a) print(b) # a = a * b a *= b print(a) print(b) =================================================== 3) Relational Operators ======================== # also called as "comparison operators" # <, >, <=, >=, ==, != # Binary Operators # return a value ==> Boolean value (True/False) a = 12 b = 13 c = 12 print(a < b) # True print(a > b) # False print(a <= b) # either a < b or a == b print(a <= c) print(a >= b) # either a > b or a == b print(a == b) # False print(a != b) # True ============================================= Logical Operators: ================== Logical and Operator: ===================== # Logical operators: three # and # or # not # In java: && (and), || (or) and ! (not) # and/or ==> Binary operators # not ==> unary operator # and/or/not: boolean, integer, float, complex, strings print(True and True) # True print(True and False) # False print(False and True) # False print(False and False) # False # any non-zero value (+eve/-eve) should be "True" # zero value ==> False # when logical and can define on boolean values, the output ==> boolean value # when the logical and can define with integers, the output ==> integer value # when the left hand side operand is "non-zero" value, the output ==> "right-side operand" value # when the left side operand is "0",the output = '0' (without checking the second) print(10 and -10) # -10 print(10 and 0) # 0 print(-10 and -1) # -1 print(0 and -10) # 0 print(0.1 and -1.9) print(0-0j and 1-2j) print('a' and 'b') print('a' and '') ========================================================= Website: https://www.ashokit.in/home Free Python Training 📅 Start Date : Today (04-Nov-2024) ⏰ Class Time: 08:00 PM (IST) ✍️ Zoom Link : https://bit.ly/3Yj8eXe 🔥 For Python BackupVideos (599 INR) : https://rzp.io/rzp/4YMKic7 👉 Join in Our WhatsApp Channel : https://bit.ly/49wCWje