फॉर्मैटेड स्ट्रिंग लिटरल

Python में Regular Expressions

Maria Eugenia Inzaugarat

Data Scientist

f-strings

  • न्यूनतम सिंटैक्स
  • स्ट्रिंग के पहले f लगाएँ

way = "code"
method = "learning Python faster"
print(f"Practicing how to {way} is the best method for {method}")
Practicing how to code is the best method for learning Python faster
Python में Regular Expressions

टाइप कन्वर्ज़न

  • अनुमत कन्वर्ज़न:
    • !s (string रूप)
    • !r (प्रिंटेबल रिप्रेज़ेंटेशन वाला string, यानी quotes सहित)
    • !a (!r जैसा, पर non-ASCII कैरेक्टर्स escape करता है)

 

name = "Python"

print(f"Python is called {name!r} due to a comedy series")
Python is called 'Python' due to a comedy series
Python में Regular Expressions

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

  • स्टैंडर्ड फॉर्मैट स्पेसिफ़ायर:
    • e (वैज्ञानिक संकेतन, जैसे 5 10^3)
    • d (डिजिट, जैसे 4)
    • f (फ़्लोट, जैसे 4.5353)

 

number = 90.41890417471841

print(f"In the last 2 years, {number:.2f}% of the data was produced worldwide!")
In the last 2 years, 90.42% of the data was produced worldwide!
Python में Regular Expressions

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

 

  • datetime

 

from datetime import datetime
my_today = datetime.now()
print(f"Today's date is {my_today:%B %d, %Y}")
Today's date is April 14, 2019
Python में Regular Expressions

इंडेक्स लुकअप

family = {"dad": "John", "siblings": "Peter"}
print("Is your dad called {family[dad]}?".format(family=family))
Is your dad called John?

 

  • इंडेक्स लुकअप के लिए quotes लगाएँ: family["dad"]
print(f"Is your dad called {family[dad]}?")
NameError: name 'dad' is not defined
Python में Regular Expressions

एस्केप सीक्वेंस

  • एस्केप सीक्वेंस: बैकस्लैश \
print("My dad is called "John"")
SyntaxError: invalid syntax

 

my_string = "My dad is called \"John\""
My dad is called "John"
Python में Regular Expressions

एस्केप सीक्वेंस

family = {"dad": "John", "siblings": "Peter"}
  • f-strings में बैकस्लैश मान्य नहीं है
print(f"Is your dad called {family[\"dad\"]}?")
SyntaxError: f-string expression part cannot include a backslash

 

print(f"Is your dad called {family['dad']}?")
Is your dad called John?
Python में Regular Expressions

इनलाइन ऑपरेशंस

  • लाभ: expressions evaluate करें और functions inline कॉल करें
my_number = 4
my_multiplier = 7
print(f'{my_number} multiplied by {my_multiplier} is {my_number * my_multiplier}')
4 multiplied by 7 is 28
Python में Regular Expressions

फंक्शंस कॉल करना

def my_function(a, b):
  return a + b
print(f"If you sum up 10 and 20 the result is {my_function(10, 20)}")
If you sum up 10 and 20 the result is 30
Python में Regular Expressions

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

Python में Regular Expressions

Preparing Video For Download...