Lesson – 100 : Python Operators

Pythonમાં પ્રોગ્રામિંગ કરતી વખતે “Operator” એક ખૂબ જ મહત્વનો ભાગ ભજવે છે. Operator એટલે કોઈ value અથવા variable પર કરવામાં આવતી ક્રિયા (operation). Pythonમાં ઘણા પ્રકારના operators છે, જેનો ઉપયોગ ગણિત, સરખામણી, logical ચેક, assignment વગેરે માટે થાય છે.

python operators


🔹 Python Operators શું છે?

Operator એ એવી સિમ્બોલ અથવા keyword છે જે values અને variables પર કાર્ય કરે છે.
જે value પર operator કાર્ય કરે તેને operand કહેવામાં આવે છે.

ઉદાહરણ:

 
a = 10 b = 5 print(a + b)

અહીં:

  • + એ operator

  • a અને b_operand


🧮 Python Operatorsનાં પ્રકાર

Pythonમાં મુખ્યત્વે 7 પ્રકારના operators છે:

  1. Arithmetic Operators

  2. Assignment Operators

  3. Comparison (Relational) Operators

  4. Logical Operators

  5. Bitwise Operators

  6. Membership Operators

  7. Identity Operators

આપણું પ્રત્યેક operatorને વિગતે સમજીએ.


1️⃣ Arithmetic Operators (ગણિતીય ઓપરેટર)

Operator વર્ણન ઉદાહરણ
+ Addition (જોડાણ) 10 + 5 = 15
- Subtraction (બાદબાકી) 10 – 5 = 5
* Multiplication (ગુણાકાર) 10 * 5 = 50
/ Division (ભાગાકાર) 10 / 5 = 2.0
% Modulus (શેષ) 10 % 3 = 1
** Exponent (ઘાત) 2 ** 3 = 8
// Floor Division 10 // 3 = 3

2️⃣ Assignment Operators (મૂલ્ય સોંપવા માટે)

Operator વર્ણન
= value assign કરે
+= value increase કરે
-= value decrease કરે
*= value multiply કરીને assign
/= divide કરીને assign
%= remainder assign
**= exponent assign
//= floor division assign

ઉદાહરણ:

 
a = 10 a += 5 # હવે a = 15

3️⃣ Comparison Operators (સરખામણી માટે)

આ operators બે values સરખાવે છે અને True અથવા False return કરે છે.

Operator અર્થ
== બન્ને value સમાન છે?
!= value અલગ છે?
> greater than
< less than
>= greater or equal
<= less or equal

ઉદાહરણ:

 
10 > 5 # True

4️⃣ Logical Operators (તાર્કિક ઓપરેટર)

Operator વર્ણન
and બંને condition True હોય ત્યારે True
or કોઈ એક condition True હોય તો True
not conditionનું વિપરીત જવાબ આપે

ઉદાહરણ:

 
x = 10 y = 5 print(x > 5 and y < 10) # True

5️⃣ Bitwise Operators

આ operators binary (bit-level) પર કાર્ય કરે છે.

Operator નામ
& AND
` `
^ XOR
~ NOT
<< Left Shift
>> Right Shift

6️⃣ Membership Operators

કોઈ value list, tuple અથવા stringમાં છે કે નથી તે ચેક કરે.

Operator અર્થ
in value હાજર છે
not in value હાજર નથી

ઉદાહરણ:

 
"A" in "APPLE" # True

7️⃣ Identity Operators

બે objects memoryમાં same છે કે નહીં તે તપાસે.

Operator અર્થ
is same object?
is not same નથી?

ઉદાહરણ:

 
a = [1,2,3] b = a a is b # True

Python Operators દ્વારા આપણે ગણિત, logic, comparison, assignment વગેરે ક્રિયાઓ સરળતાથી કરી શકીએ છીએ. Pythonમાં operatorsનો યોગ્ય ઉપયોગ કરવાથી coding વધુ સરળ અને અસરકારક બને છે.