Header Ads Widget

riti-advertiesment

Python Literals kya hain? Literal in hindi?

 पायथन Literals


पायथन Literals को एक Variable या constant में दिए गए डेटा के रूप में परिभाषित किया जा सकता है। पायथन निम्नलिखित Literal का समर्थन करता है:

1.String literals:

Example:
"RITI" , '12345'  
Types of Strings:
a) Single-line String- 
Example:
text1='hello'  

b) Multi-line String 
Example:

text1='hello\    
user'    
print(text1)  

c) Using triple quotation marks
Example:
str1='''''welcome  
to  
RITI''    
print str1

Numeric literals:

x = 0b10100 #Binary Literals  
y = 100 #Decimal Literal   
z = 0o215 #Octal Literal  
u = 0x12d #Hexadecimal Literal  
  
#Float Literal  
float_1 = 100.5   
float_2 = 1.5e2  
  
#Complex Literal   
a = 5+3.14j  
  
print(x, y, z, u)  
print(float_1, float_2)  
print(a, a.imag, a.real)    
Boolean literals:
x = (1 == True)  
y = (2 == False)  
z = (3 == True)  
a = True + 10  
b = False + 10  
  
print("x is", x)  
print("y is", y)  
print("z is", z)  
print("a:", a)  
print("b:", b)  

Special literals

Python में एक विशेष Literals भी है i.e., None.

"None" का उपयोग उस फ़ील्ड को बनाने के लिए किया जाता है जिसे बनाया नहीं गया है। इसका उपयोग पायथन में सूचियों के अंत के लिए भी किया जाता है।

Example - Special Literals

val1=10    
val2=None    
print(val1)     
print(val2)  

Literal Collections

पायथन चार प्रकार के Literals संग्रह प्रदान करता है जैसे सूची (List) Literals, टुपल(Tuple) Literals, डिक्ट(Dict) Literals, और सेट(set) Literals

List:

List में विभिन्न प्रकार के डेटा शामिल कर सकते हैं।  List में Store Date अल्पविराम (,) द्वारा अलग किए गए हैं और वर्ग कोष्ठक ([ ]) के भीतर संलग्न हैं। हम विभिन्न प्रकार के डेटा को एक सूची में संग्रहीत कर सकते हैं.
list=['John',678,20.4,'Peter']    
list1=[456,'Andrew']    
print(list)    
print(list + list1)  

Dictionary:

पायथन डिक्शनरी डेटा को की-वैल्यू पेयर में स्टोर करती है.
It is enclosed by curly-braces {} and each pair is separated by the commas(,).
Example

dict = {'name': 'Pater', 'Age':18,'Roll_nu':101}  
print(dict)  

Tuple:


पायथन टपल विभिन्न डेटा-प्रकार का एक संग्रह है। यह अपरिवर्तनीय है जिसका अर्थ है कि इसे निर्माण के बाद संशोधित नहीं किया जा सकता है।
It is enclosed by the parentheses () and each element is separated by the comma(,).
Example

tup = (10,20,"Dev",[2,3,4])  
print(tup)  

Set:

पाइथन सेट(Set) अनियोजित (Unordered) डेटासेट का संग्रह है।
It is enclosed by the {} and each element is separated by the comma(,).
Example: - Set Literals

set = {'apple','grapes','guava','papaya'}  
print(set)

Web Designing Course