Identifier in Python

Identifier in Python

A name in python program is called identifier. We have to use names to identify variable or to identify class or to identify methods/functions or to identify modules; that names itself called as identifiers which can be used for identification. So a name in a python program is called identifier.

पायथन प्रोग्राम में एक नाम आइडेंटिफायर कहलाता है। हमें वैरियेबल की पहचान करने के लिए या क्लास की पहचान करने के लिए या मेथड/फंक्शन की पहचान करने या मॉड्यूल की पहचान करने के लिए नामों का उपयोग करना है, उस नाम को ही आइडेंटिफायर कहा जाता है, जिसका उपयोग पहचान के लिए किया जा सकता है। एक पायथन प्रोग्राम में एक नाम को आइडेंटिफायर कहा जाता है।
For example:

>>> Item_name = "Python" #A String 
>>> Item_qty = 10 #An Integer
>>> Item_value = 230.50 #A floating point 

Important: Which of the following are valid Python identifiers?

निम्नलिखित में से कौन वैध पायथन आइडेंटिफायर हैं?

 a = 100# Valid a is normal variable 
_a = 200# Valid underscore a 
_ _a = 300# Valid double underscore a 
_ _a _ _ = 400 # Valid double underscore a double score 

Here in Python there is specific convention with underscore with identifier.

यहां पायथन में आइडेंटिफायर के साथ अंडरस्कोर के साथ विशिष्ट कन्वेंशन है।

  1. In Python, if any variable starts with underscore symbol, these variables are considering as

protected variables.

पायथन में, यदि कोई वैरियेबल अंडरस्कोर सिम्बल से स्टार्ट होता है, तो इन वैरियेबल को प्रोटेक्टेड वैरियेबल माना

जाता है।

  1. In Python, if any variable starts with two underscore symbol, these variables are considering as

private variables.

पायथन में, यदि कोई वैरियेबल दो अंडरस्कोर सिम्बल से स्टार्ट होता है, तो इन वैरियेबल को प्राईवेट वैरियेबल माना

जाता है।

  1. In Python, if any variable starts with two underscore symbol and end with two underscore

symbol, these variables are considering as magic variables.

पायथन में, यदि कोई वैरियेबल दो अंडरस्कोर सिम्बल से स्टार्ट और दो अंडरस्कोर सिम्बल से समाप्त होता है, तो इन वैरियेबल को मैजिक वैरियेबल माना जाता है।

For example: _ _ abc_ _ # is called language level pre-defined magic variable in Python

_ _add_ _ () # is called language level pre-defined magic method in python

Numbers – नम्बर्स

Integers, floating point numbers and complex numbers fall under Python numbers category. They are defined as int, float and complex class in Python.

इंटीगर, फ्लोटिंग पॉइंट नंबर और कॉम्प्लेक्स नंबर पायथन नंबर की श्रेणी में आते हैं। उन्हें पायथन में int, float और काम्प्लेक्स क्लास के रूप में परिभाषित किया गया है।

Integers –इंटीगर(int data type)

A number without decimal point, these numbers are called integral numbers or whole numbers. If wants to represent an integral value, then we go for int data type.

दशमलव बिंदु के बिना एक संख्या, इन संख्याओं को अभिन्न संख्या या संपूर्ण कहा जाता है। यदि हम एक अभिन्न मूल्य का प्रतिनिधित्व करना चाहते हैं तो हम int डेटा टाइप का प्रयोग करते हैं।

For example

>>> x = 23 
>>> type (x) 
<class 'int'>

Float data type – फ्लोट डेटा टाइप

We can use float data type to store the data which is available in the form of the numbers with the decimal places.

हम float data type का उपयोग उन डेटा को संग्रहीत करने के लिए कर सकते हैं जो दशमलव स्थानों के साथ संख्याओं के रूप में उपलब्ध हैं।

For example:

>>> pyFloat = 12.2345 
>>> type (pyFloat) 
<class 'float'>
>>> 4.2  
4.2
>>> type (4.2) 
<class 'float'>
>>> 4. 
4.0
>>> .2
0.2 

Complex Numbers – कॉम्प्लेक्स नम्बर्स
(‘complex’ datatype)

In Python, Complex data type is used to store complex numbers data. The format of complex data type is a+bj or a-bj.

पायथन में, Complex data type का उपयोग कॉम्प्लेक्स नंबर डेटा को स्टोर करने के लिए किया जाता है। कॉम्प्लेक्स डेटा टाइप का प्रारूप a+bj या a-bj है।

a + bj (here j = -1)

Here ‘a’ is called real part and ‘b’ is called imaginary part. यहाँ ‘a’ को वास्तविक भाग कहा जाता है और ‘b’ को काल्पनिक भाग कहा जाता है।

Complex literals are written as real part +/- imaginary part, where the imaginary part is terminated with a ‘j’ or ‘J’. The real part is technically optional, so the imaginary part may appear on its own. Here ‘a’ and ‘b’ contain integer or floating point values.

काम्प्लेक्स लिटरल को वास्तविक भाग +/- काल्पनिक भाग के रूप में लिखा जाता है, जहाँ कल्पनाशील ‘J’ या ‘J’ के साथ अलग होता है। रियलपार्ट तकनीकी रूप से वैकल्पिक है, इसलिए काल्पनिक हिस्सा अपने आप दिखाई दे सकता है। यहाँ हम ‘a’ और ‘b’ में पूर्णांक या फ्लोटिंग पॉइंट वैल्यू हैं।

For example:उदाहरण के लिए

>>>pyC = 1 + 2j
>>> type (pyC) 
<class 'complex'>
>>> c1 = 25.3 + 2j    # valid 
>>> c1 = 23 + 12.32j  # valid 
>>> c1 = 25.3 + 22.3j # valid

In real part, we can use decimal or binary or octal or hexa decimal values, but imaginary part should be specified only decimal form.

वास्तविक भाग में, हम दशमलव या बाइनरी या ऑक्टल या हेक्सा दशमलव वैल्यू का उपयोग कर सकते हैं, लेकिन काल्पनिक भाग को केवल दशमलव प्रकार निर्दिष्ट किया जाना चाहिए।

bool – बूल

To represent logical values like true or false then we go for bool data type. In bool data type allowed values are ‘True’ and ‘False’. In Python, in true value starting letter ‘t should be Capital ‘T’, in false value starting letter ‘f should be capital ‘F’ otherwise PVM gives an error message.

सही या गलत जैसे तार्किक मूल्यों का प्रतिनिधित्व करने के लिए हम बूल डेटा टाइप का प्रयोग करते हैं। बूल डेटा टाइप में एलाउड वैल्यू “True’ और ‘False’ होते हैं। पायथन में, सही वैल्यू के शुरुआती अक्षर ‘t’ आवश्यक रूप से कैपिटल.T, गलत वैल्यू के शुरुआती अक्षर ‘f आवश्यक रूप से कैपिटल ‘F’ होना चाहिए अन्यथा PVM एक एरर मैसेज देता है।

For example:

>>> a = true 
Traceback (most recent call last): 
File "<pyshell#0>", line 1, in <module>
a = true 
NameError: name 'true' is not defined 
>>> a = True 
>>>type (a)
<class 'bool'>

Set is a class treated as data type. A set data type represents unordered collection of elements or to represent a group of unique values as a single entity then we should go for set data type. It is commonly used in membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference.

सेट एक वर्ग है जिसे डेटा टाइप माना जाता है। एक सेट डेटा टाइप एलीमेंट के अनऑर्डर संग्रह का प्रतिनिधित्व करता है या एकल इकाई के रूप में यूनिक वैल्यू के एक समूह का प्रतिनिधित्व करता है तो हमें सेट डेटा टाइप के लिए जाना चाहिए। यह आमतौर पर मेम्बरशिप टेस्टिंग में उपयोग किया जाता है, एक सिक्वेन्स से डुप्लिकेट को हटाता है, और अर्थमेटिक ऑपरेशन जैसे कि इंटरसेक्शन, यूनियन, डिफरेन्स, और सिमेट्रिक अंतर की गणना करता है।

A set does not accept duplicate elements.

एक सेट डुप्लीकेट एलीमेंट को स्वीकार नहीं करता है।

A set is defined by values separated by comma inside braces {}.

एक सेट को ब्रेस {} के अंदर कॉमा द्वारा अलग किए गए वैल्यूज द्वारा परिभाषित किया गया है।

A set data type element can be modified.

एक सेट डेटा टाइप एलीमेंट को संशोधित किया जा सकता है।

A set does not maintain insertion order. We cannot determine in which order set elements displayed.

एक सेट इंसर्शन आर्डर को बनाए नहीं रखता है। हम यह निर्धारित नहीं कर सकते कि किस क्रम में सेट किए गए एलीमेंट प्रदर्शित किए गए हैं।

A set data type provides dynamic size.

एक सेट डेटा टाइप डॉयनॉमिक आकार प्रदान करता है।

A set object does not allow indexing & slicing.

एक सेट ऑब्जेक्ट इंडेक्सिंग और स्लाइसिंग की अनुमति नहीं देता है।

To convert other type of elements to set type elements we used a predefined function called Set ()

सेट टाइप एलीमेंट को सेट करने के लिए अन्य प्रकार के एलीमेंट को परिवर्तित करने के लिए हमने set ()नामक

पूर्वनिर्धारित फंक्शन का उपयोग किया जाता है।

Create a set: एक सेट बनाएं

>>> #A non empty set 
>>> n = set ([0, 1, 2, 3, 4, 5])
>>> print (n) 
{0, 1, 2, 3, 4, 5} 
>>> type (n)# to know the type of n 
<class 'set'>
>>> id (n) 
47019480

We can create an object of set by using set () function.

हम set() फंक्शन का उपयोग करके सेट का ऑब्जेक्ट बना सकते हैं।

>>> #A new empty set 
>>> setx = set () 
>>> print(setx) 
set ()

Note: If we use a={}, then, PVM treated as dictionary type but not an empty set.

यदि हम a = [} का उपयोग करते हैं, उसके बाद, पीवीएम को शब्दकोश टाइप माना जाता है लेकिन खाली सेट नहीं।

For example:

s = {} 
>>> s
{}

Set have unique values. They eliminate duplicates.

सेट के यूनिक वैल्यू हैं। वे डुप्लीकेट को खत्म करते हैं।

>>> a = {1,2,2,3,3,3}
>>>a
{1, 2, 3} 
>>> n = { 'aa', 'bb', 'cc' } 
>>> n ={ 'aa', 'cc', 'bb' } 
>>> n = { 'aa', 'bb', 'cc', 'aa' } 
>>> n ={ 'aa', 'cc', 'bb' } 
>>> n = { 'a', 'p', 'p', '1', 'e'}
>>> n
{'e', '1', 'p', 'a'}

Observe the difference between these two set definitions:

इन दो सेट परिभाषाओं के बीच के अंतर को देखें:

>>> n = {'a', 'p','p', 'l', 'e'} 
>>> n ={'e', 'p', 'a', 'l'} 
>>>set ('apple')
{'e', 'l', 'p', 'a'}
>>> {'apple'}
{'apple'} 

Add item(s) in set: सेट में आइटम जोड़ें

>>>#A new empty set 
>>> colors=set()
>>>#Add a single member 
>>> colors.add("Red") 
>>>print (colors)
{ 'Red'} 

Update item(s) in set:सेट में आइटम अपडेट करें

>>>#Add multiple items 
>>>colors.update (["Blue", "Green"]) 
>>>print (colors) 
{'Green', 'Red', 'Blue'}

Remove item(s) from set:सेट में आइटम को रिमूव करना

pop (), remove () and discard () functions are used to remove individual item from a Python set. See the following examples:

pop (), remove () और discard () फंक्शन का उपयोग पायथन सेट से इंडिविजुअल आइटम को हटाने के लिए किया जाता है। निम्नलिखित उदाहरण देखें

  1. pop () function: Using this function remove and return an orbitary set element.

इस फंक्शन का उपयोग करना और एक आर्बिटेरी सेट एलीमेंट को वापस करना।

>>> numset =set ( [0, 1,2] ) 
>>> numset.pop () 
0 
>>>print (numset) 
{1,2} 
>>>numset.pop()
1
>>>print (numset)
{2}
>>> numset.pop ()
2
>>>numset.pop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop from an empty set
  1. remove () function: Using this function, remove an element from a set; It must be a member.

इस फंक्शन का उपयोग करते हुए, एक सेट से एक एलीमेंट को हटा दें, यह एक सदस्य होना चाहिए।

>>> nums = set ( [0, 1, 2, 3, 4, 5] ) 
>>> nums. remove (2) 
>>> print (nums) 
{0, 1, 3, 4, 5} 
>>> nums. remove (4) 
>>> print (nums)
{0, 1, 3, 5}
  1. discard () function: Remove an element from a set if it is a member.

एक सेट से एक एलीमेंट निकालें अगर यह एक सदस्य है।

>>> nums = set ( [0, 1, 2, 3, 4, 5] ) 
>>>nums.discard (2) 
>>> print (nums)
{0, 1, 3, 4, 5} 
>>>nums.discard (4) 
>>> print (nums) 
{0, 1, 3, 5}

For example:

>>> nums = set ( [0, 1, 2, 3, 4, 5] ) 
>>> nums.remove 
<built-in method remove of set object at 0x03027878>
>>> nums.remove (6)
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    nums.remove (6)
KeyError: 6
>>> nums.discard (6)
>>>

Set Size and Membership – आकार और मेम्बरशिप सेट करें

The len () function returns the number of elements in a set, and the ins and not in operators can be used to test for membership:

len ()फंक्शन एक सेट में एलीमेंट की संख्या लौटाता है, और मेंबरशिप के लिए परीक्षण करने के लिए इन ऑपरेटर का उपयोग नहीं किया जा सकता है।

>>> x = {11, 22, 33} 
>>> len (x)
3
>>>11 in x 
True 
>>>11not in x 
False

Clear items in set – सेट में क्लियर आइटम

clear () function removes all items from set.

clear () फंक्शन सभी आइटम को सेट में रिमूव कर देता है।

For example:

>>> s = { 'a', 'b', 'c', 'd' } 
>>>s.clear () 
>>> s
set () 

Chapter wise Model Paper Link

About Me