change language👆
Data Type
Variable जो value store करता है
Data Type: उस value का प्रकार (जैसे number, string, list, etc.)
int x = 5 पूरा नंबर (integer)
float pi = 3.14 दशमलव नंबर (decimal)
str name = "Ram" टेक्स्ट (string)
bool flag = True सही या गलत (True/False)
list marks = [90, 85] एक ordered, changeable collection
tuple t = (1, 2, 3) ordered, लेकिन unchangeable
set s = {1, 2, 3} unordered, unique values only
dictionary d = {'a':1, 'b':2} key-value pair
आप type का use करके डाटा type का पता कर सकते है
जैसे - a=2
print(type(a)) # output = int
Operators-
Python में operators (ऑपरेटर) का इस्तेमाल calculations, comparison, और logic apply करने के लिए किया जाता है।
मतलब जब आप दो values के साथ कोई काम (जोड़ना, तुलना करना, check करना) करते हो — वहाँ operators का use होता है।
Arithmetic operators
Addition +
Subtraction -
Multiply *
Division /
Floor Division //
Power **
Modulus (remainder) %
Assignment operators(मान देने वाले ऑपरेटर)
= equal
+= x+=2 means x=x+2
-= x-=2 means x=x-2
*= x*=2 means x=x*2
/= x/=2 means x=x?2
**= x**=2 means x=x**2
//= x//=2 means x=x//2
Comparison operators
== equal
!= not equal
< less than
> greater than
<= less than equal to
>= greater than equal to
Logical operators
and - दोनों condition True होनी चाहिए
or - कोई एक भी condition True होनी चाहिए
not - जो है उसका उल्टा कर देता है (True → False)
score = 80 rank = 10 if score > 90 and rank <20:
#यदि score ज्यादा है 90 से और rank कम है 20 से
print("Good Effort") else:
#अन्यथा
print(f"not good")
score = 80 rank = 10 if score > 90 and rank <20: print("Good Effort") else: print(f"not good")
good_result = False
#good-result = नहीं है
if not good_result:
# यदि नहीं है good_result ( हाँ good_result नहीं है क्युकी हमने उपर लिखा है false )
print("not good ")
Identity operators
दो object same हैं या नहीं
is - same
is not - not same
a = [1, 2, 3]
b = a
c = [1, 2, 3]
print(a is b) # True (b points to same object as a)
print(a is c) # False (c is a different object with same content)
print(a == c) # True (values same हैं, लेकिन object अलग है)
print(a is not c)
➤चलो मै आपको एक interesting सवाल पूछता हूँ मुझे पक्का विश्वास है की आप गलत करेंगे मेरे विश्वास को मत तोडना 😅
Q.नीचे दिए गए कोड का आउटपुट क्या होगा True या False ?
x=2
y=4/2
print(x is y)
अपने python Environment में चेक करे Terminal में क्या आउटपुट आया
क्यों भाई क्या हुआ चकरा गये न ?
Membership operators
कोई value मौजूद है या नहीं
in - included
not in - not included
word = "welcome"
print("l" in word) # True
print("z" not in word) # True
Bitwise operators
Bitwise Operators Python में ऐसे operators होते हैं जो numbers पर bit level पर काम करते हैं — यानी 0 और 1 के रूप में binary में।
AND (&)
p = 5 # binary: 0101 q = 3 # binary: 0011 print(p & q) #and
Breakdown-
& का अर्थ होता है दोनों condition में 1 हो तो ही 1 होगा
यहाँ 5 =0101
3=0011
तब p&q =0001 और यह 6 का binary होता है
OR
p = 5 # binary: 0101 q = 3 # binary: 0011 print(p | q) #or
Breakdown-
| का अर्थ होता है दोनों condition में किसी में भी हो तो ही 1 होगा
यहाँ 5 =0101
3=0011
तब p&q =0111 और यह 1 का binary होता है
XOR(^)
p = 5 # binary: 0101
q = 3 # binary: 0011
print(p ^ q)
^ का अर्थ अगर binary अलग है तो 1 otherwise 0
यहाँ 5 =0101
3=0011
तब p^q =0110 और यह 7 का binary होता है
NOT(~)
p = 5 # binary: 0101
print(~p)
NOT binary को change कर देता है 0 को 1 में और 1 को 0 में
अब सवाल यह आता है की Bitwise काम कहा आते है
Bitwise के use -Encryption & decryption, Image processing , low level tasks
हम अब यूजर का मेसेज encrypt , decrypt करते है
message = input('write your message')
key = 123
encrypted = []
for char in message:
encrypted.append(chr(ord(char) ^ key))
print("Encrypted:", ''.join(encrypted))
decrypted = []
for char in encrypted:
decrypted.append(chr(ord(char) ^ key))
print("Decrypted:", ''.join(decrypted))
Breakdown-
message = input('write your message')
यूजर मेसेज भेजता है
key = 123
यह नंबर हम अपनी मर्जी से सेट कर सकते है जिससे की हम encrypt कर सके आगे use करेंगे तब समझ जायेंगे
encrypted = []
encrypted name की एक लिस्ट बनाते है जिसमे हम मेसेज को encrypt करने के बाद ऐड करेंगे
for char in message:
लो char में से , message
encrypted.append(chr(ord(char) ^ key))
encrypted लिस्ट में ऐड करो (char को ASCII number में बदले और key से xor करो , chr= वापस करैक्टर में बदलो जिससे की यह unreadable बन जायेगा
print("Encrypted:", ''.join(encrypted))
,".join = यह किसी लिस्ट को str से जोड़ने में काम आता है
decrypted = []
descrypted name की लिस्ट
for char in encrypted:
decrypted.append(chr(ord(char) ^ key))
अब फिर से इसे रिपीट करो जिससे की वो वापस सही टेक्स्ट में आ जाये
जेसे की 2 को -1 से multiply करने पर -2 आता है और फिर से -1 से multiply करने से वापस 2 आ जाता है
print("Decrypted:", ''.join(decrypted))
प्रिंट करो decrypted लिस्ट को
🎯 Task for You: (give answer in comment)
1. int को float , str में कैसे बदला जाता है ?
2. int और str को एक साथ में प्रिंट केसे कराया जाता है ?
No comments:
Post a Comment