Python Operators
เคเค เคเคชเคฐेเคเคฐ เคเค เคช्เคฐเคคीเค (เคฏा เคिเคจ्เคน) เคนै เคो เคเค เคเคชเคฐेเคถเคจ (เคฏा เคाเคฐ्เคฏ) เคเคฐเคคा เคนै।
An operator is a symbol (or sign) that performs an operation (or action).
เคฏเคฆि เคोเค เคเคชเคฐेเคเคฐ เคเคเคฒ เคเคฌ्เคेเค्เค เคฏा เคฎाเคจ เคชเคฐ เคाเคฐ्เคฏ เคเคฐเคคा เคนै, เคคो เคเคธे เคฏूเคจเคฐी (unary) เคเคชเคฐेเคเคฐ เคเคนा เคाเคคा เคนै। เคฏเคฆि เคोเค เคเคชเคฐेเคเคฐ เคฆो เคเคฌ्เคेเค्เค เคฏा เคฎाเคจों เคชเคฐ เคाเคฐ्เคฏ เคเคฐเคคा เคนै, เคคो เคเคธे เคฌाเคเคจเคฐी (binary) เคเคชเคฐेเคเคฐ เคเคนเคคे เคนैं। เคฏเคฆि เคोเค เคเคชเคฐेเคเคฐ เคคीเคจ เคเคฌ्เคेเค्เค เคฏा เคฎाเคจों เคชเคฐ เคाเคฐ्เคฏ เคเคฐเคคा เคนै, เคคो เคเคธे เคเคฐเคจเคฐी (ternary) เคเคชเคฐेเคเคฐ เคเคนเคคे เคนैं।
If an operator operates on a single object or value, it is called a unary operator. If an operator operates on two objects or values, it is called a binary operator. If an operator operates on three objects or values, it is called a ternary operator.
Types
- Arithmetic Operators
-
Comparison (Relational) Operators
- Boolean (Logical) Operators
- Bitwise Operators
- Assignment Operators
- Membership Operators
- Identity Operators
Arithmetic Operators:-
เคเคจ เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคธाเคฎाเคจ्เคฏ เค ंเคเคเคฃिเคคीเคฏ เคเคฃเคจाเคं เคैเคธे เคोเคก़, เคुเคฃा เคเคฆि เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เค ंเคเคเคฃिเคค เคเคชेเคฐเคเคฐ เคตे เคिเคจ्เคน เคนैं เคिเคจเคा เคเคชเคฏोเค เคเคฃिเคค เคเคฐ เคช्เคฐोเค्เคฐाเคฎिंเค เคฎें เคธंเค्เคฏाเคं เคฏा เคตेเคฐिเคเคฌเคฒ्เคธ เคชเคฐ เคฌेเคธिเค เคเคฃिเคคीเคฏ เคाเคฐ्เคฏ เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เคंเคช्เคฏूเคเคฐ เคช्เคฐोเค्เคฐाเคฎिंเค เคฎें, เคเคจ เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคธंเค्เคฏाเคค्เคฎเค เคฎाเคจों เคฎें เคฌเคฆเคฒाเคต เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เคฏे เคเคชเคฐेเคเคฐ เคเคฃिเคคीเคฏ เคเคฃเคจा เคเคฐเคจे เคฎें เคฎौเคฒिเค เคนैं เคเคฐ เคชाเคฏเคฅเคจ, เคธी, เคाเคตा เคเคฐ เค เคจ्เคฏ เคช्เคฐोเค्เคฐाเคฎिंเค เคญाเคทाเคं เคฎें เคต्เคฏाเคชเค เคฐूเคช เคธे เคเคชเคฏोเค เคिเค เคाเคคे เคนैं।
These operators are used to perform common arithmetic calculations like addition, multiplication etc. Arithmetic operators are symbols or characters used in mathematics and programming to perform basic mathematical operations on numbers or variables. In computer programming, these operators are used to manipulate numeric values. These operators are fundamental in performing mathematical calculations and are widely used in programming languages like Python, C, Java, and more.
- Exponentiation ( ** )
- Multiplication ( * )
- Division ( / )
-
Floor (Integer) Division ( // )
- Modulus ( % )
- Addition ( + )
- Subtraction ( - )
Arithmetic operators in detail
Comparison Operators:-
เคฏे เคฌाเคเคจเคฐी เคเคชเคฐेเคเคฐ्เคธ เคนैं เคो เคฆो เคฎाเคจों เคी เคคुเคฒเคจा เคเคฐเคคे เคนैं เคเคฐ True เคฏा False เคฎें เคชเคฐिเคฃाเคฎ เคฆेเคคे เคนैं। เคคुเคฒเคจा เคเคชเคฐेเคเคฐ, เคिเคจ्เคนें เคฐिเคฒेเคถเคจเคฒ เคเคชเคฐेเคเคฐ เคे เคฐूเคช เคฎें เคญी เคाเคจा เคाเคคा เคนै, เคा เคเคชเคฏोเค เคช्เคฐोเค्เคฐाเคฎिंเค เคฎें เคฆो เคฎाเคจों เคी เคคुเคฒเคจा เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เคตे เคคुเคฒเคจा เคे เคเคงाเคฐ เคชเคฐ เคเค เคฌूเคฒिเคฏเคจ เคชเคฐिเคฃाเคฎ (เคฏा เคคो 'เคธเคนी' เคฏा 'เคเคฒเคค') เคฒौเคाเคคे เคนैं। เคเคจ เคคुเคฒเคจा เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เค เค्เคธเคฐ เคธเคถเคฐ्เคค เคฌเคฏाเคจों, เคฒूเคชों เคเคฐ เค เคจ्เคฏ เคจिเคฏंเคค्เคฐเคฃ เคธंเคฐเคเคจाเคं เคฎें เคจिเคฐ्เคฃเคฏ เคฒेเคจे เคเคฐ เคฎूเคฒ्เคฏों เคฏा เคตेเคฐिเคเคฌเคฒ्เคธ เคे เคฌीเค เคธंเคฌंเคงों เคे เคเคงाเคฐ เคชเคฐ เคช्เคฐोเค्เคฐाเคฎ เคे เคช्เคฐเคตाเคน เคो เคจिเคฏंเคค्เคฐिเคค เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै।
These are binary operators that compare two values and result in True or False. Comparison operators, also known as relational operators, are used in programming to compare two values or expressions. They return a Boolean result (either `True` or `False`) based on the comparison. These comparison operators are often used in conditional statements, loops, and other control structures to make decisions and control the flow of a program based on the relationships between values or variables.
- Less Than ( < )
-
Less Than or Equals To ( <= )
- Greater Than ( > )
-
Greater Than or Equals To ( >= )
- Equals To ( == )
- Not Equals To ( != )
Comparison Operators in detail
Boolean (Logical) Operators:-
เคเคจ เคเคชเคฐेเคเคฐ्เคธ เคा เคเคชเคฏोเค เคเคฎ्เคชाเคंเคก เคंเคกीเคถเคจ्เคธ (เคเค เคถเคฐ्เคค เคो เคฆो เคฏा เค เคงिเค เคถเคฐ्เคคों เคो เคฎिเคฒाเคเคฐ เคฌเคจा เคนो) เคो เคฌเคจाเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เคเคฌ เคฌूเคฒिเคฏเคจ เคเคชเคฐेเคเคฐ्เคธ เคฌूเคฒ เคाเคเคช เคे เคฎाเคจ เคैเคธे True เคฏा False เคชเคฐ เคเคชเคฐेเคถเคจ เคเคฐเคคे เคนैं เคคो เคฌूเคฒ เคाเคเคช เคा เคฐिเคเคฒ्เค เคฆेเคคे เคนैं। เคชाเคฏเคฅเคจ เคฎें เคฌूเคฒिเคฏเคจ เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคฌूเคฒिเคฏเคจ เคฎाเคจों (เคธเคนी เคเคฐ เคเคฒเคค) เคชเคฐ เคคाเคฐ्เคिเค เค्เคฐिเคฏाเคं เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เคชाเคฏเคฅเคจ เคฎें เคคीเคจ เคฎुเค्เคฏ เคฌूเคฒिเคฏเคจ เคเคชเคฐेเคเคฐ เคนैं: `เคเคฐ`, `เคฏा`, เคเคฐ `เคจเคนीं`। เคเคจ เคฌूเคฒिเคฏเคจ เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เค เค्เคธเคฐ เคธเคถเคฐ्เคค เคฌเคฏाเคจों, เคฒूเคชों เคเคฐ เค เคจ्เคฏ เคธ्เคฅिเคคिเคฏों เคฎें เคिเคฏा เคाเคคा เคนै เคเคนां เคเคชเคो เคुเค เคถเคฐ्เคคों เคी เคธเค्เคाเค เคฏा เคूเค เคे เคเคงाเคฐ เคชเคฐ เคจिเคฐ्เคฃเคฏ เคฒेเคจे เคी เคเคตเคถ्เคฏเคเคคा เคนोเคคी เคนै। เคตे เคเคชเคे เคชाเคฏเคฅเคจ เคช्เคฐोเค्เคฐाเคฎो เคฎें เค เคงिเค เคเคिเคฒ เคเคฐ เคธाเคฐ्เคฅเค เคคเคฐ्เค เคฌเคจाเคจे เคฎें เคเคชเคी เคธเคนाเคฏเคคा เคเคฐเคคे เคนैं।
These operators are used to create compound conditions (a condition made up of two or more conditions). Boolean operators return a result of bool type when they operate on values of bool type, such as True or False. Boolean operators in Python are used to perform logical operations on boolean values (True and False). Python has three main boolean operators: `and`, `or`, and `not`. These boolean operators are often used in conditional statements, loops, and other situations where you need to make decisions based on the truth or falsity of certain conditions. They help you create more complex and meaningful logic in your Python programs.
- Logical And ( and )
- Logical Or ( or )
- Logical Not ( not )
Bitwise Operators:-
เคฏे เคเคชเคฐेเคเคฐ्เคธ เคฌिเค्เคธ เคชเคฐ เคเคชเคฐेเคถเคจ เคเคฐเคคे เคนैं। เคฎाเคจों เคो เคชเคนเคฒे เคฌाเคเคจเคฐी เคฎें เคฌเคฆเคฒा เคाเคคा เคนै เคซिเคฐ เคैเคฒเคुเคฒेเคถเคจ เคिเคฏा เคाเคคा เคนै। เคฏे เคเคชเคฐेเคเคฐ्เคธ เคेเคตเคฒ เคเคจ्เคिเคเคฐ เคฎाเคจों เคชเคฐ เคाเคฐ्เคฏ เคเคฐเคคे เคนैं। เคชाเคฏเคฅเคจ เคฎें เคฌिเคเคตाเคเค़ เคเคชเคฐेเคเคฐ เคเคชเคो เคชूเคฐ्เคฃांเค เคฎाเคจों เคे เคฌिเค्เคธ เคฎें เคนेเคฐเคซेเคฐ เคเคฐเคจे เคी เค เคจुเคฎเคคि เคฆेเคคे เคนैं। เคเคจ เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เค เค्เคธเคฐ เคจिเคฎ्เคจ-เคธ्เคคเคฐीเคฏ เคช्เคฐोเค्เคฐाเคฎिंเค เคฎें เคिเคฏा เคाเคคा เคนै เคเคฐ เคฌाเคเคจเคฐी เคกेเคा เคे เคธाเคฅ เคाเคฎ เคเคฐเคคे เคธเคฎเคฏ เคฏा เคฌिเค-เคธ्เคคเคฐीเคฏ เคธंเคाเคฒเคจ เคो เคถाเคฎिเคฒ เคเคฐเคจे เคตाเคฒे เคुเค เค เคฒ्เคोเคฐिเคฅเคฎ เคो เคฒाเคू เคเคฐเคคे เคธเคฎเคฏ เคตिเคถेเคท เคฐूเคช เคธे เคเคชเคฏोเคी เคนोเคคे เคนैं। เคฌिเคเคตाเคเค เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคคเคฌ เคिเคฏा เคाเคคा เคนै เคเคฌ เคเคชเคो เคกेเคा เคे เคฌाเคเคจเคฐी เคช्เคฐเคคिเคจिเคงिเคค्เคต เคे เคธाเคฅ เคाเคฎ เคเคฐเคจे เคी เคเคตเคถ्เคฏเคเคคा เคนोเคคी เคนै เคฏा เคเคฌ เคเคช เคจिเคฎ्เคจ-เคธ्เคคเคฐीเคฏ เคฌिเค เคนेเคฐเคซेเคฐ เคเคฐเคจा เคाเคนเคคे เคนैं। เคตे เค เค्เคธเคฐ เคंเคช्เคฏूเคเคฐ เคนाเคฐ्เคกเคตेเคฏเคฐ, เคกेเคा เคเคฎ्เคช्เคฐेเคถเคจ, เคเคจ्เค्เคฐिเคช्เคถเคจ เคเคฐ เคฌเคนुเคค เคुเค เคธे เคธंเคฌंเคงिเคค เค เคจुเคช्เคฐเคฏोเคों เคฎें เคฆेเคे เคाเคคे เคนैं।
These operators operate on bits. The values are first converted to binary then the calculations are done. These operators work only on integer values. Bitwise operators in Python allow you to manipulate individual bits of integer values. These operators are often used in low-level programming and are particularly useful when working with binary data or implementing certain algorithms that involve bit-level operations. Bitwise operators are used when you need to work with the binary representation of data or when you want to perform low-level bit manipulation. They are often seen in applications related to computer hardware, data compression, encryption, and more.
- Bitwise AND ( & )
- Bitwise OR ( | )
- Bitwise XOR ( ^ )
- Bitwise NOT ( ~ )
-
Bitwise Left Shift ( << )
- Bitwise Right Shift ( >> )
Assignment Operator ( = ):-
เคฏเคน เคเคชเคฐेเคเคฐ เคฆाเคं เคธाเคเคก เคे เคฎाเคจ เคो เคฌाเคं เคธाเคเคก เคे เคตेเคฐिเคเคฌเคฒ เคฎें เคธ्เคोเคฐ เคเคฐเคคा เคนै। เคชाเคฏเคฅเคจ เคฎें เค เคธाเคเคจเคฎेंเค เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคตेเคฐिเคเคฌเคฒ्เคธ เคฎें เคฎाเคจ เคฐเคเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै। เคตे เคिเคธी เคฎाเคจ เคे เค เคธाเคเคจเคฎेंเค เคो เคเคฃिเคคीเคฏ เคเคชเคฐेเคถเคจ เคฏा เค เคจ्เคฏ เคเคชเคฐेเคถเคจ เคे เคธाเคฅ เคोเคก़เคคे เคนैं। เคฏे เค เคธाเคเคจเคฎेंเค เคเคชเคฐेเคเคฐ เคเค เคนी เคเคฐเคฃ เคฎें เคเคชเคฐेเคถเคจ เคเคฐเคคे เคธเคฎเคฏ เคตेเคฐिเคเคฌเคฒ्เคธ เคो เคเคจเคे เคตเคฐ्เคคเคฎाเคจ เคฎूเคฒ्เคฏों เคे เคเคงाเคฐ เคชเคฐ เค เคชเคกेเค เคเคฐเคจे เคा เคเค เคธंเค्เคทिเคช्เคค เคคเคฐीเคा เคช्เคฐเคฆाเคจ เคเคฐเคคे เคนैं।
This operator stores the value of the right side in the variable on the left side. Assignment operators in Python are used to assign values to variables. They combine the assignment of a value with a mathematical operation or other operations. These assignment operators provide a concise way to update variables based on their current values while performing an operation in a single step.
syntax: variable = value
example: x = 5
hint: stores value 5 in variable x
Membership Operators:-
เคฏे เคเคชเคฐेเคเคฐ्เคธ เคिเคธी เคฎाเคจ เคो เคिเคธी เคฎाเคจों เคे เคธเคฎूเคน เคैเคธे string เคฏा list เคฎें เคोเคเคคे เคนैं เคเคฐ เคฎाเคจ เคे เคฎिเคฒเคจे เคฏा เคจ เคฎिเคฒเคจे เคชเคฐ True เคฏा False เคฎें เคชเคฐिเคฃाเคฎ เคฆेเคคे เคนैं। เคชाเคฏเคฅเคจ เคฎें เคฎेเคฎ्เคฌเคฐเคถिเคช เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคฏเคน เคชเคฐीเค्เคทเคฃ เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เคोเค เคฎाเคจ เคฏा เคเคฒिเคฎेंเค เคिเคธी เค्เคฐुเคช (เคธीเค्เคตेंเคธ) เคा เคธเคฆเคธ्เคฏ เคนै, เคैเคธे เคธ्เค्เคฐिंเค, เคธूเคी เคฏा เคเคชเคฒ। เคฎेเคฎ्เคฌเคฐเคถिเคช เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เค เค्เคธเคฐ เคธเคถเคฐ्เคค เคฌเคฏाเคจों เคเคฐ เคฒूเคชों เคฎें เคिเคฏा เคाเคคा เคนै เคคाเคि เคฏเคน เคांเคा เคा เคธเคे เคि เคोเค เคเคฒिเคฎेंเค เคเคธ เคธ्เคฅिเคคि เคे เคเคงाเคฐ เคชเคฐ เคตिเคถिเคท्เค เคाเคฐ्เคฐเคตाเค เคเคฐเคจे เคธे เคชเคนเคฒे เค्เคฐुเคช (เคธीเค्เคตेंเคธ) เคฎें เคฎौเคूเคฆ เคนै เคฏा เคจเคนीं।
These operators search for a value in a set of values such as a string or list and return True or False if the value is found or not found. Membership operators in Python are used to test whether a value or element is a member of a sequence, such as a string, list, or tuple. Membership operators are often used in conditional statements and loops to check if an element is present in a collection before taking specific actions based on that condition.
-
In Membership ( in )
- Not In Membership ( not in )
Identity Operators:-
เคฏे เคเคชเคฐेเคเคฐ्เคธ เคเคฌ्เคेเค्เค्เคธ เคी เคเคเคกेंเคिเคी (เคฎेเคฎोเคฐी เคเคก्เคฐेเคธ) เคो เคेเค เคเคฐเคคे เคนैं เคเคฐ เคธเคฎाเคจ เคนोเคจे เคฏा เคจ เคนोเคจे เคे เคเคงाเคฐ เคชเคฐ True เคฏा False เคฎें เคชเคฐिเคฃाเคฎ เคฆेเคคे เคนैं। เคชाเคฏเคฅเคจ เคฎें, เคเคเคกेंเคिเคी เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคฏเคน เคจिเคฐ्เคงाเคฐिเคค เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เค्เคฏा เคฆो เคตेเคฐिเคเคฌเคฒ เคฏा เคเคฌ्เคेเค्เค เคเค เคนी เคฎेเคฎोเคฐी เคธ्เคฅाเคจ เคो เคธंเคฆเคฐ्เคญिเคค (เคฆเคฐ्เคถाเคคे) เคเคฐเคคे เคนैं เคฏा เคเค เคนी เคชเคนเคाเคจ เคฐเคเคคे เคนैं। เคเคเคกेंเคिเคी เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เค เค्เคธเคฐ เคเคฌ्เคेเค्เค เคी เคคुเคฒเคจा เคเคฐเคจे เคเคฐ เคฏเคน เคांเคเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เค्เคฏा เคตे เคเค เคนी เคเคฆाเคนเคฐเคฃ เคนैं, เคाเคธเคเคฐ เคเคฌ เคฒिเคธ्เค, เคกिเค्เคถเคจเคฐी เคเคฐ เคฏूเคเคฐ-เคกिเคซाเคंเคก เค्เคฒाเคธेเค เคैเคธी เคชเคฐिเคตเคฐ्เคคเคจเคถीเคฒ เคเคฌ्เคेเค्เค เคธे เคจिเคชเคเคคे เคนैं। เคง्เคฏाเคจ เคฐเคें เคि เคฏे เคเคชเคฐेเคเคฐ เคชเคนเคाเคจ เคी เคाँเค เคเคฐเคคे เคนैं, เคธเคฎाเคจเคคा เคी เคจเคนीं। เคฆो เคเคฌ्เคेเค्เค เคฎूเคฒ्เคฏ เคฎें เคธเคฎाเคจ เคนो เคธเคเคคी เคนैं เคฒेเคिเคจ เคเคจเคी เคชเคนเคाเคจ เคธเคฎाเคจ เคจเคนीं เคนो เคธเคเคคी।
These operators check the identity (memory address) of the objects and return True or False depending on whether they are equal or not. In Python, identity operators are used to determine if two variables or objects reference the same memory location or have the same identity. Identity operators are often used to compare objects and check if they are the same instance, especially when dealing with mutable objects like lists, dictionaries, and user-defined classes. Keep in mind that these operators check for identity, not equality. Two objects can be equal in value but not have the same identity.
- Is Identitical ( is )
- Is Not Identitical ( is not )
Comments
Post a Comment