पोज़िशनल फॉर्मेटिंग

Python में Regular Expressions

Maria Eugenia Inzaugarat

Data scientist

स्ट्रिंग फॉर्मेटिंग क्या है?

  • स्ट्रिंग इंटरपोलेशन

  • पहले से तय टेक्स्ट में कस्टम स्ट्रिंग या वैरिएबल जोड़ें:

custom_string = "String formatting"
print(f"{custom_string} is a powerful technique")
String formatting is a powerful technique
  • उपयोग:
    • ग्राफ में शीर्षक
    • संदेश या त्रुटि दिखाएँ
    • किसी फंक्शन को स्टेटमेंट पास करें
Python में Regular Expressions

फॉर्मेटिंग के तरीके

  • पोज़िशनल फॉर्मेटिंग
  • फॉर्मेटेड स्ट्रिंग लिटरेल्स
  • टेम्पलेट मेथड
Python में Regular Expressions

पोज़िशनल फॉर्मेटिंग

  • प्लेसहोल्डर को वैल्यू से बदलें

  • str.format()

 

print("Machine learning provides {} the ability to learn {}".format("systems", "automatically"))
Machine learning provides systems the ability to learn automatically
Python में Regular Expressions

पोज़िशनल फॉर्मेटिंग

  • शुरुआती स्ट्रिंग और मेथड में पास की गई वैल्यू, दोनों के लिए वैरिएबल्स इस्तेमाल करें
my_string = "{} rely on {} datasets"
method = "Supervised algorithms"
condition = "labeled"
print(my_string.format(method, condition))
Supervised algorithms rely on labeled datasets
Python में Regular Expressions

वैल्यू रीऑर्डर करना

  • वैल्यू को रीऑर्डर करने के लिए प्लेसहोल्डर्स में इंडेक्स नंबर दें
print("{} has a friend called {} and a sister called {}".format("Betty", "Linda", "Daisy"))
Betty has a friend called Linda and a sister called Daisy

 

print("{2} has a friend called {0} and a sister called {1}".format("Betty", "Linda", "Daisy"))
Daisy has a friend called Betty and a sister called Linda
Python में Regular Expressions

नेम्ड प्लेसहोल्डर्स

  • प्लेसहोल्डर्स के लिए नाम निर्दिष्ट करें
tool="Unsupervised algorithms"
goal="patterns"
print("{title} try to find {aim} in the dataset".format(title=tool, aim=goal))
Unsupervised algorithms try to find patterns in the dataset
Python में Regular Expressions

नेम्ड प्लेसहोल्डर्स

my_methods = {"tool": "Unsupervised algorithms", "goal": "patterns"}
print('{data[tool]} try to find {data[goal]} in the dataset'.format(data=my_methods))
Unsupervised algorithms try to find patterns in the dataset
Python में Regular Expressions

फॉर्मेट स्पेसिफायर

  • उपयोग होने वाला डेटा टाइप बताएं: {index:specifier}
print("Only {0:f}% of the {1} produced worldwide is {2}!".format(0.5155675, "data", "analyzed"))
Only 0.515568% of the data produced worldwide is analyzed!

 

print("Only {0:.2f}% of the {1} produced worldwide is {2}!".format(0.5155675, "data", "analyzed"))
Only 0.52% of the data produced worldwide is analyzed!
Python में Regular Expressions

datetime फॉर्मेट करना

 

from datetime import datetime
print(datetime.now())
datetime.datetime(2019, 4, 11, 20, 19, 22, 58582)

 

print("Today's date is {:%Y-%m-%d %H:%M}".format(datetime.now()))
Today's date is 2019-04-11 20:20
Python में Regular Expressions

अभ्यास करते हैं!

Python में Regular Expressions

Preparing Video For Download...