पायथन के ट्रिपल कोट्स स्ट्रिंग्स को कई लाइनों तक फैलाने की अनुमति देकर बचाव में आते हैं, जिसमें वर्बेटिम NEWLINEs, TABs, और कोई अन्य स्पेशल कैरेक्टर्स शामिल हैं।
ट्रिपल कोट्स का सिंटैक्स तीन लगातार सिंगल या डबल कोट्स से मिलकर बनता है।
उदाहरण
#!/usr/bin/python para_str = """this is a long string that is made up of several lines and non-printable characters such as TAB ( \t ) and they will show up that way when displayed. NEWLINEs within the string, whether explicitly given like this within the brackets [ \n ], or just a NEWLINE within the variable assignment will also show up. """ print para_str
आउटपुट
जब उपरोक्त कोड निष्पादित होता है, तो यह निम्नलिखित परिणाम देता है।
ध्यान दें कि कैसे हर एक स्पेशल कैरेक्टर को उसके प्रिंटेड फॉर्म में बदल दिया गया है, ठीक अंतिम NEWLINE तक "up." और क्लोजिंग ट्रिपल कोट्स के बीच स्ट्रिंग के अंत में। यह भी ध्यान दें कि NEWLINEs या तो एक लाइन के अंत में स्पष्ट कैरिज रिटर्न या इसके एस्केप कोड (\n) के साथ होते हैं:
this is a long string that is made up of several lines and non-printable characters such as TAB ( ) and they will show up that way when displayed. NEWLINEs within the string, whether explicitly given like this within the brackets [ ], or just a NEWLINE within the variable assignment will also show up.
रॉ स्ट्रिंग्स बैकस्लैश को बिल्कुल स्पेशल कैरेक्टर नहीं मानते। आप रॉ स्ट्रिंग में जो भी कैरेक्टर डालते हैं वह वैसे ही रहता है जैसा आपने लिखा था:
उदाहरण
#!/usr/bin/python print 'C:\\nowhere'
आउटपुट
जब उपरोक्त कोड निष्पादित होता है, तो यह निम्नलिखित परिणाम देता है:
C:\nowhere
अब आइए रॉ स्ट्रिंग का उपयोग करें। हम r'expression' में एक्सप्रेशन डालेंगे:
उदाहरण
#!/usr/bin/python print r'C:\\nowhere'
आउटपुट
जब उपरोक्त कोड निष्पादित होता है, तो यह निम्नलिखित परिणाम देता है:
C:\\nowhere