शुरू करेंमुफ़्त में शुरू करें

Methods के साथ strings में बदलाव

Methods वे खास functions होते हैं जो objects से जुड़े होते हैं. कुछ data types में ऐसे methods होते हैं जो डेटा में बदलाव करने के लिए उपयोगी होते हैं. उदाहरण के लिए, .upper() method किसी string का uppercase वर्ज़न लौटाकर string वैरिएबल्स को बदलता है. .lower() method string का lowercase वर्ज़न लौटाता है.

city = 'New York'
print(city.lower())

new york

Strings के लिए एक और बहुत उपयोगी method है .format(), जो string में मौजूद curly brackets को उसके अंदर पास किए गए arguments से बदल देता है.

city = 'New York'
print("City: {}".format(city))

City: New York

Methods का उपयोग करके string वैरिएबल्स में बदलाव का अभ्यास करें और साथ ही American इतिहास से जुड़ा एक मज़ेदार तथ्य भी जानें!

यह अभ्यास पाठ्यक्रम का हिस्सा है

MATLAB उपयोगकर्ताओं के लिए Python

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Print the lowercase version of this Jeopardy clue
clue = 'Signer of the Dec. of Indep., framer of the Constitution of Mass., second President of the United States'

print(clue.____)
कोड संपादित करें और चलाएँ