What is Print Function and Escape Sequences ?

Print Function  

अगर हमे स्क्रीन पे कुछ भी प्रिंट करवाना है  तो इसके लिए print function का उपयोग करते है |

जैसे की हम जानते है अलग अलग प्रोग्रामिंग लैंग्वेज मे  प्रिंट करने क लिए अलग अलग सिंटेक्स या फंक्शन  होते है | और जैसे की हम जानते है की java , c , c++ , मे प्रिंट करने क लिए कम से कम 4 से 5 लाइन का प्रोग्राम लिखना पड़ता है लेकिन पाइथन मे ऐसा नहीं है | आप केवल प्रिंट कमांड दे कर कुछ भी string  प्रिंट करवा सकते हो | प्रिंट करने के लिए print के बाद parent thesis के अंदर Single Quotes या double quotes लगाकर कोई भी  string  पास कर सकते है |

syntax  for  python :-      print (“hello”)

यहाँ हम Single Quotes या double quotes दोनों प्रयोग कर सकते है |

Single Quotes या double quotes का प्रयोग करने के लिए कुछ पॉइंट को जानना जरुरी है |

  • Single Quotes के अंदर आप  double quotes का उपयोग कर सकते है लेकिन सिंगल कोट्स के अंदर सिंगल कोट्स का उपयोग नहीं कर सकते |  (you can use “double quotes ” inside ‘single quotes’)
  • ठीक ऐसे ही double quotes  के अंदर आप Single Quotes का उपयोग कर सकते है लेकिन डबल कोट्स के अंदर डबल कोट्स का उपयोग नहीं कर सकते | (you can use “single quotes ” inside ‘double quotes’)

अगर हम Single Quotes के अंदर Single quotes और double quotes के अंदर double quotes प्रयोग करेंगे तो invalid syntax error आती है |

for example :-

1. print("welcome "thetechnicalnotes"")   #syntax error 

solution of this syntax error :- 
print("welcome 'thetechnicalnotes'")

output :- welcome 'thetechnicalnotes'

2. print('plzzz 'visit my site'') #syntax error 

solution of this syntax error :- 
print('plzzz "visit my site"')

output :- plzzz "visit my site"

Escape Sequences 

जैसा की हमने पढ़ा की हम सिंगल कोट्स के अंदर सिंगल कोट्स और डबल कोट्स के अंदर डबल कोट्स का उपयोग नहीं कर सकते | तो इसके solution के लिए हम escape sequence का use करते है | अगर डबल कोट्स के अंदर backslash double quotes (\”) लिखे  तो error नहीं आएगी |

हमारे पास निचे दिए गए कुछ Escape Sequence है |

Escape Sequence :- 

  1. \’     (backslash single quotes)
  2. \”    (backslash double quotes)
  3. \\    (double backslash)
  4.  \n   (backslash n )
  5. \t     (backslash  t)
  6. \b    (backslash  b)

इन सबका अलग अलग meaning होता है जैसा की backslash double quotes का अर्थ होता है double quotes
ठीक इसी प्रकार backslash Single quotes का अर्थ होता है single quotes और double backslash का अर्थ होता है backslash |  इसी प्रकार

backslash n का अर्थ होता है new line

backslash t का अर्थ होता है tab

backslash b का अर्थ होता है backspace

#---------------------Exercise------------------------
# ------------ print these following lines--------------
# this is \\ double backslash
# these is /\/\/\/\/\ mountain
# he is  awesome
# \" \n \t \' 

# solution :-

print ("this is \\\\ double backslash")
print ("these is /\\/\\/\\/\\/\\ mountain")
print ("he is \t awesome ")
print ("\\\" \\n \\t \\\'")