Skip to main content

All About Strings in python in Hindi - Quiz

In this tutorial we are going to study All About Strings..

  •  इस ट्यूटोरियल में हम ऑल अबाउट स्ट्रिंग्स का अध्ययन करने जा रहे हैं।


We are providing this blog in both languages Hindi and English.

  • हम यह ब्लॉग हिंदी और अंग्रेजी दोनों भाषाओं में उपलब्ध करा रहे हैं।


The hand written notes and quiz on strings is provided below.

  • हाथ से लिखे नोट्स और स्ट्रिंग्स पर प्रश्नोत्तरी नीचे दी गई है।


Here’s what you’ll learn in this tutorial: Python provides a rich set of operators, functions, and methods for working with strings. When you are finished with this tutorial, you will know how to access and extract portions of strings, and also be familiar with the methods that are available to manipulate and modify string data.

  • इस ट्यूटोरियल में आप जो सीखेंगे वह यहां दिया गया है: पायथन स्ट्रिंग्स के साथ काम करने के लिए ऑपरेटरों, कार्यों और विधियों का एक समृद्ध सेट प्रदान करता है। जब आप इस ट्यूटोरियल के साथ समाप्त कर लेंगे, तो आपको पता चल जाएगा कि स्ट्रिंग्स के हिस्सों तक कैसे पहुंचें और निकालें, और उन तरीकों से भी परिचित हों जो स्ट्रिंग डेटा में हेरफेर और संशोधित करने के लिए उपलब्ध हैं।




Define strings :

 objects that contain sequences of character data. Processing character data is integral to programming. It is a rare application that doesn’t need to manipulate strings at least to some extent.

  • ऑब्जेक्ट जिसमें वर्ण डेटा के अनुक्रम होते हैं। प्रोसेसिंग कैरेक्टर डेटा प्रोग्रामिंग का अभिन्न अंग है। यह एक दुर्लभ अनुप्रयोग है जिसे कम से कम कुछ हद तक स्ट्रिंग्स में हेरफेर करने की आवश्यकता नहीं है।



String Information :

The string is a data type in Python. A string is a sequence of characters enclosed in quotes. We can primarily, write a string in three ways:

  • स्ट्रिंग पायथन में एक डेटा प्रकार है। एक स्ट्रिंग उद्धरणों में संलग्न वर्णों का एक क्रम है। हम मुख्य रूप से एक स्ट्रिंग को तीन तरीकों से लिख सकते हैं:


1. Single quoted strings : a = ‘jerry’ 

2. Double quoted strings : b = “jerry” 

3. Triple quoted strings : c = ‘’’ jerry ‘’’




String Indexing :

A string in Python can be sliced for getting a part of the string, The index in a string starts from 0 to (length-1) in Python.

  • पायथन में एक स्ट्रिंग को स्ट्रिंग का एक हिस्सा प्राप्त करने के लिए काटा जा सकता है, एक स्ट्रिंग में इंडेक्स पायथन में 0 से (लंबाई -1) तक शुरू होता है।


Assume the string :

S = " foobar "






  •  To get a single character in a string, we can use index inside   'square bracket'.

  •   Index value should be an integer from 0 to size of string.


  •   एक स्ट्रिंग में एकल वर्ण प्राप्त करने के लिए, हम 'square bracket' के अंदर      अनुक्रमणिका का उपयोग कर सकते हैं।

      

  •   अनुक्रमणिका मान 0 से लेकर स्ट्रिंग के आकार तक का पूर्णांक होना चाहिए।



>> S[0]

      " f "

>> S[1]

      " o "

>> S[3]

      " b "


Important Note :

1]  Index value starts from 0 not from 1.

2]  To get last character in string we can use -1.


1] इंडेक्स वैल्यू 0 से शुरू होती है न कि 1 से।

2] स्ट्रिंग में अंतिम वर्ण प्राप्त करने के लिए हम -1 का उपयोग कर सकते हैं।




String Slicing :

SYNTAX : str_object[start_pos : end_pos]

The slicing starts with the start_pos index and ends at end_pos index. The step parameter is used to specify the steps to take from start to end index.

  • स्लाइसिंग start_pos अनुक्रमणिका से प्रारंभ होती है और end_pos अनुक्रमणिका पर समाप्त होती है। स्टेप पैरामीटर का उपयोग स्टार्ट से एंड इंडेक्स तक जाने के लिए स्टेप्स को निर्दिष्ट करने के लिए किया जाता है।


EX 1 :

s = "HelloWorld"
first_five_chars = s[:5]
print(first_five_chars)


Output = Hello

 EX 2 :

s = "HelloWorld"
third_to_fifth = s[2:5]
print(third_to_fifth)


Output = llo


Important Note :

1]  In string slicing the (end_pos) is not included.

2]  It slice upto (end_pos) - 1.


1]  स्ट्रिंग स्लाइसिंग में (end_pos) शामिल नहीं है।

२]  यह (end_pos) - १ तक स्लाइस करता है।




Logical Operator :

  • " in " keyword is used to check if one string is in another string.


  • " in " expression is a logical expression that returns TRUE or FALSE and can be used in an if statement.

  • "in" कीवर्ड का उपयोग यह जांचने के लिए किया जाता है कि एक स्ट्रिंग दूसरी स्ट्रिंग में है या नहीं।

  • "in" अभिव्यक्ति एक तार्किक अभिव्यक्ति है जो TRUE या FALSE लौटाती है और इसका उपयोग if statement में किया जा सकता है।


EX 1 :

fruit = "banana"
print('n' in fruit)  # it checks 'n' present in fruit or not 
if it is present it returns true


Output = True 

EX 2 :

fruit = "banana"
print('m' in fruit)  # it returns false because m is not present in "banana"


Output = False

EX 3 :

fruit = "banana"
if 'a' in fruit:  # We are saying that if 'a' is present in fruit
 i.e("banana") then print Found It!
    print("Found It!")


Output = Found It! 



String Methods :

1. len() function : It returns the length of the string,  

ex: len(‘jerry’)        #Returns 5

2. endswith(“rry”) : This function tells whether the variable string ends with the string “rry” or not. If string is “jerry”, it returns for “rry” since jerry ends with rry.

3. count(“c”) : It counts the total number of occurrences of any character.

4. capitalize() : This function capitalizes the first character of a given string

5. find(word) : This function finds a word and returns the index of first occurrence of that word in the string.

6. replace(oldword, newword) : This function replaces the old word with the new word in the entire string.

7. isupper() : The isupper() method returns "True" if all characters in string are uppercase, Otherwise it written "False".

8. islower() : The islower() method returns "True" if all characters in string are lowercase, Otherwise it written "False".


Quiz :

1]  What does the following Python Program print out?
     (Choose Only One Option)

str1 = "good"
str2 = "morning!"

greet = str1 + str2
print(greet)


  • morning!
  • goodmorning!


2]  What does the following Python code print out?
    (Choose only One Option)

print(len('per')*7)

  • perperperperperperper


3]  What does the following Python code print out?
    (Choose only One Option)

str = "I LOVE PYTHON"
print(str.isupper())
  • False
  • True


# Give The Quiz Answer in Comments..

# Comment Down for Handwritten Notes..


Comments

Popular posts from this blog

ds

  < html > < body >     < form name = "FRM1" >         Enter name         < input type = "text" name = "t1" >< br >< br >         Enter Address < br >         < textarea name = "t2" placeholder = "PERMANENT ADDRESS" ></ textarea >< br >< br >         Enter Telephone Number         < input type = "tel" name = "t3" maxlength = "10" >< br >< br >         Enter Email Address         < input type = "email" name = "t4" pattern = "[A-Z a-z]{5}-[@]{1}-[.]{1}" placeholder = "deeshank37@gmail.com" >< br >< br >         < input type = "button" name = "b1" value = "Submit" onClick = "chk()" >     </ form >     < script type = "text/javascript" >   ...