Skip to main content

Python Strings in hindi (Part -6)

Subscribe

* indicates required
                                                String in Python


Python mai hm string ka use krte hai text information ko store krne ke liye jaise ki name, jaisa ki hm jante hai Python mai character nhi hota python mai character ko string of length one mana jata hai.
String ko single quotation mai bhi represent kr skte hai aur double quotation mai bhi represent kr skte hai. Let's see an example..
  
print('hey')

print("hey")

agar hame multiline string ko assign krna hai to ham wo bhi kr skte hai
example:


a = """hey, this is rishabh gupta
and I will teach you python from scratch 
enjoy the blog"""
print(a)

output

hey, this is rishabh gupta
and I will teach you python from scratch 
enjoy the blog

Python ki string ek array jaise hoti hai iska mtlb ye hua ki hm python string ki indexing kr skte hai (indexing krne ka mtlb hua position dena) , aur us string se hm koi bhi letter nikal skte hai , aaiye isko aur clear banane ke liye example ka sahara lete hai.

mystr="rishabh is good boy"
print(mystr)
rishabh is good boy
"ye baat hamesa yaad rakhiyega ki python follows the zero based index system jiska mtlb hai ki python m indexing 
zero se hoti hai , to hm hamesha zero se count karenge one se nhi "
"Python mai space bhi count hota hai"

print(mystr[4])
a
ap dekh skte hai ki 4th position mai a hai [0-r ,1-i,2-s,3-h,4-a,5-b,6-h,7-"space",8-i,and so on]
aur example ki madad se python string ko clear samjhte hai
----------------------------------------------------------------------
print(mystr[0:18])
rishabh is good bo

# 0:18 mai 0 include hota hai lekin 18 exclude hota hai yani ki is example mai 18th position ko nhi gina jayega
------------------------------------------------------------------
print(mystr[0:19])
rishabh is good boy
#isme 19 exclude hai mtlb 18th position tak gina jayega aur usme "rishabh is good boy" pur complete sentence aata hai
 -------------------------------------------------------------------------
print(mystr[
0:19:2])
rsahi odby
#isme hm actually ek character ko skip kra rhe hai (skipping one character)
#:2 ka mtlb hai ki ek character chhod ke print kro agar :3 hota mtlb 2 character ko chhod ke print kro
# isliye ap dekh skte hai ki r ke baad i skip ho gya hai aur s hai , s ke baad h skip ho gya aur a hai and so on.....
------------------------------------------------------------------------------------------------
print(mystr[::])
rishabh is good boy
#ye ek dusra tarika hai string print karane ka , agar man lo apko number count krna nhi aata hai ya fir apko number count krna bahut alasya wala kaam lagta hai to ap is tarah bhi likh skte hai.
-----------------------------------------------------------------------------------------------------
print(mystr[::-1])
yob doog si hbahsir
#-1 basically string ko ulta kr deta hai ,to isme piche se character print hona start ho gye 
#dekhiye ye sb chije apko manually remember krni hogi
-------------------------------------------------------------------------------------
         String Methods

print(mystr.isalnum())
False
#isme hame output false mila hai , iska mtlb ye hai ki ye jo mystr string ye alpha numeric nhi hai mtlb is string ke andar space hai 
#ham dekh skte hai ki "rishabh" ke baad space hai fir "is" hai fir space hai..., to ye string ke andar space hai is liye hame false result mil raha hai
----------------------------------------------------------------------------------
rig="jaijavanjaikisan"
#yaha hamne ek dusri string li hai aur ab ham isme operation krenge 
-------------------------------------------------------------------------------
print(rig.isalnum())
True
#to ab hm dekh skte hai ki is string mai space nhi hai , isliye hame result true mil raha hai.
----------------------------------------------------------------------------------------------
print(rig.isalpha())
True
#is alpha check krta hai ki string purely alphabet hai ki nhi , aur hamari string purely alphabet hai isliye hame result true mila hai
-------------------------------------------------------------------------
print(mystr.endswith("boy"))
True
#mystr boy se end ho raha hai isliye it return true 
-----------------------------------------------------------------------------
print(mystr.count("b"))
2
#count function string ko count krne ke liye hai, mystr mai 2 b hai, isliye hame 2 return hua
-------------------------------------------------------------------------------
print(mystr.count("k"))
0
#0 "k" hai mystr mai
--------------------------------------------------------------------------
print(mystr.capitalize())
Rishabh is good boy
#capitalize function string ko capatilize kr deta hai, yani string ke pahle character ko capital letter mai convert kr deta hai.
------------------------------------------------------------------------------------------

pk="Ziddi hu MAI"
print(pk.lower())
ziddi hu mai
#convert to lower case
-----------------------------------------------------------------------------
sk="pagal hu mai"
print(sk.upper())
PAGAL HU MAI
#convert to upper case
--------------------------------------------------------------------------------
print(mystr.replace(
"good" , "bad"))
rishabh is bad boy
#as a name suggest replace function are used to replace the string
-----------------------------------------------------------------
Python mai kafi saare string function hai maine kuch hi mention kiye hai , ap python ki original documentaion mai jake check kr skte hai
https://docs.python.org/2/library/string.html

Bonus:----
MethodDescription
capitalize()Converts the first character to upper case
casefold()Converts string into lower case
center()Returns a centered string
count()Returns the number of times a specified value occurs in a string
encode()Returns an encoded version of the string
endswith()Returns true if the string ends with the specified value
expandtabs()Sets the tab size of the string
find()Searches the string for a specified value and returns the position of where it was found
format()Formats specified values in a string
format_map()Formats specified values in a string
index()Searches the string for a specified value and returns the position of where it was found
isalnum()Returns True if all characters in the string are alphanumeric
isalpha()Returns True if all characters in the string are in the alphabet
isdecimal()Returns True if all characters in the string are decimals
isdigit()Returns True if all characters in the string are digits
isidentifier()Returns True if the string is an identifier
islower()Returns True if all characters in the string are lower case
isnumeric()Returns True if all characters in the string are numeric
isprintable()Returns True if all characters in the string are printable
isspace()Returns True if all characters in the string are whitespaces
istitle()Returns True if the string follows the rules of a title
isupper()Returns True if all characters in the string are upper case
join()Joins the elements of an iterable to the end of the string
ljust()Returns a left justified version of the string
lower()Converts a string into lower case
lstrip()Returns a left trim version of the string
maketrans()Returns a translation table to be used in translations
partition()Returns a tuple where the string is parted into three parts
replace()Returns a string where a specified value is replaced with a specified value
rfind()Searches the string for a specified value and returns the last position of where it was found
rindex()Searches the string for a specified value and returns the last position of where it was found
rjust()Returns a right justified version of the string
rpartition()Returns a tuple where the string is parted into three parts
rsplit()Splits the string at the specified separator, and returns a list
rstrip()Returns a right trim version of the string
split()Splits the string at the specified separator, and returns a list
splitlines()Splits the string at line breaks and returns a list
startswith()Returns true if the string starts with the specified value
strip()Returns a trimmed version of the string
swapcase()Swaps cases, lower case becomes upper case and vice versa
title()Converts the first character of each word to upper case
translate()Returns a translated string
upper()Converts a string into upper case
zfill()Fills the string with a specified number of 0 values at the beginning
he

Comments

Post a Comment

Python tutorial in hindi

Python Introduction in Hindi (Part -1)

Subscribe * indicates required Email Address *                                                PYTHON                                                                                                                                                               Python kya hai ? Python ek programming language h , to programming language kya h , dekho agar mai kisi se baat kr rha hu ya fir kisi ko kuch samjha raha hu to usse baat krne ya samjhane m mujhe kisi language ka use krna padega jaise man lo mai use hindi m samjha rha hu to yaha mai hindi language use kr rha hu  thik usi tarah computer ko samjhane ke liye mujhe kisi programming language ka use krna padega , aur PYTHON unme se ek hi hai. "  agar ap ko lagta h ki python language ka naam  python( ajgar ) ke naam pr rakha gya h to ap bahut badi galat fahmi mai ji rhe ho kyoki python ka naam ek comedy group 'montey python' se liya gya h" Python hi kyo ? Py

OOPs in Python in Hindi (Part -14)

Subscribe * indicates required Email Address *          OBJECT ORIENTED PROGRAMMING Python ek object oriented programming language hai, iska mtlb ye hai ki Python mai hr ek chiz object hai. Dekho Oops kafi confusing ho skta hai agar ap longo ko oops kafi gande tarike se padhya gya hai , mai is post ke jariye ap longo ko oops ko bahut assan shabdo mai samjhane ki pori koshish krunga.  Aayiye oops padhne se pehle kuch terms clear kr lete hai , taki ap longo ko ise padhne mai koi muskil na ho. Class and object Class ek design ya blueprint hai. Object ek real thing hai. Aayiye ise example ki madad se aur clear krte hai jaise Animal ek class hai aur cat , dog , tiger etc ye sb object hai, Animal ek real chiz nhi hai lekin object ek real chiz hai Ek example aur lete hai jaise bhot longo ke pass iPhone 11 hoga lekin ye design sirf ek baar hi kiya jata hai to ek class ke pass kai object ho skte hai. Aayiye object ko aur deep se samj

Modules and Packages in Python in Hindi (Part -16)

                    Modules and Packages Modules aur Packages sunne mai kafi fancy term lag raha hai, lekin is post ko padhne ke baad apko clear hojayega ki modules aur packages kya hai ? let's suppose apne ek python program banaya aur usse save kr diya rishabh.py name se, aur fir apne ek dusra program banaya aur ussse save kr diya gupta.py name se , to basically rishabh.py ek module ho gya aur ussi tarah gupta.py bhi ek module ho gya aur har module ke andar kuch classes hongi kuch , kuch functions honge , aur ham in classes or function ka use kr skte hai dusre program mai import statement ki madad se jo ki hm aange dekhne wale hai , to basically module .py name se save koi bhi python program hogaya, to ab baat krte hai ki packages kya hote hai , to packages basically collection of modules and empty __init__.py file hote hai, to agar upar wala example le to agar hm rishabh.py , gupta.py aur empty __init__.py file ko ek folder mai rakhe to vo folder ek Package kahelayega. module - r

Data Structure in Python in hindi (Part -7)

Subscribe * indicates required Email Address *                                                 Python Data Structure A  data structure  is a collection of different forms and different  types  of  data  that has a set of specific operations that can be performed Python mai data structure two categories mai divided hai pahla hai built in data structure (built in ka mtlb hai jo ki python ke undar hi hai hame inhe bahar se import krke lane ki koi jrurt nhi hai, aur dusra hai user defined data structure , is post mai hm python ke built in data structure ki baat krenge.                                                                                        Built-in Data Structure Lists Dictionary Tuple Set 1.Lists List basically ek container hai jisme hm bahut saare object rakh skte hai , List mai hm textual data aur numerical data dono rakh skte hai, chaliye ise aur clear banate hai ek example ki madad se , es example ko samajhne

Python Variables in hindi (Part -3)

Subscribe * indicates required Email Address *                                                 Variables Variable basically ek container hota hai jisme ap data value store krte ho . example a = "hello" b = 3 c = 3.4 To idhar ap dekh skte hai  a, b, c ye teeno variable hai , a mai hmne hello naam ki string ko store kiya hai , b mai hmne 3 ko store kiya hai aur c m hamne 3.4 ko store kiya hai ap ise aise bhi samjh skte ho ki (a) ek box h  jyisme hmne hello ko daal diya hai , i hope ki apko variable bahut acche se clear ho gya hoga.  Waise mai apko bta du ki baki programming language jaise java waha hme variable ko declare krna padta hai mtlb hme batana padta hai ki ye variable kis type ka hai jaise int , float , string, char etc. lekin python mai hme yaha batana nhi padta ki ye kis type ka hai. Int , float , string , char ka use kaha hota h let's see   inka use in value ko store krne mai hota hai. Jaise ki maine

Python for loop and while loop in hindi (Part -10)

Subscribe * indicates required Email Address *                            For loops For loop iteration ke liye use hota hai , iteration ka dusra mtlb ho skta hai repetition , agar mai poochu ki kis chiz pe iteration to answer hai , iteration over a sequence like string, list , dicitionary , tuple , sets. Syntax: for iterator_name in iterating_sequence:        Statement...... Aayiye ise example ki madad se aur clear krte hai....... ------------------------------------------------------------------------------------------ #program of for loop in string r = 'rishabh' for x in (r): print (x) output: r i s h a b h ------------------------------------------------------------------------ #program to print items in list l =[ "ram" , "shyam" , "rishabh" , "shyamlal" ] for y in l: print (y) Output: ram shyam rishabh shyamlal # Ap dekh skte hai ki kaise ye loop work kr rha hai, h

Python Syntax and Comments in Hindi (Part -2)

Subscribe * indicates required Email Address *                    Python Syntax Chalo surwat krte h dosto agar man lo apko apna naam print krana h ya fir kuch bhi print karana hai python mai to kaise kroge  , so answer is by using a print statement , jaise mera naam Rishabh Gupta hai aur mujhe  mera naam print karana hai                                     >>> print("Rishabh Gupta")                                              Rishabh Gupta    "  maine yaha double inverted comma use kiya h ap single inverted comma ya triple inverted comma bhi use kr skte ho"                               >>> print('Rishabh Gupta')                                                 Rishabh Gupta                                         >>> print('''Rishabh Gupta''')                                                   Rishabh Gupta " ye code maine Python 3.7.5 shell

Error and Exception Handling in Python in Hindi (Part -15)

Subscribe * indicates required Email Address *                                         Error and Exception Handling Python mai coding krte samay kabhi na kabhi apko error to jrur mili hogi jaise print('hello) Output: Syntax error 2+'s' Output: Type error So is tarah ki error jo python nhi samajh pa raha hai ise hm exception kahte hai. Hm is tarah ke exception ko handle kr skte hai, dekho hota kya hai jb exception aati hai to python interpreter program ko stop kr deta hai  aur error throw kr deta hai, aur hame output mai error mil jati hai , to hm error ko handle kr skte hai try aur except keyword ka use kr ke  so , try aur except error ko handle krte hai aur baki ke code ko continue rakhne mai madad krte hai. So , jb bhi apko lage ki yaha error hone ke chances hai ise try keyword ke andar rakhe, aur us exception ki handling hm except ke andar  rakhenge Aayiye ise example ki madad se aur clear krte hai... -----

Functions in Python in hindi (Part -13)

Subscribe * indicates required Email Address *                              Functions Function ek block of code hota hai jo ki us code se related operation perform krta hai. Python mai  kafi saare built in function hai jaise print(), input(), file(), int() etc , pr aap yaha khud ka function bhi create kr skte ho jise ham user - defined function kahenge. Function ko create krne ke do steps hai pehla hai defining a function or dusra hai Calling the function. Python function ko hm define krte hai def keyword ki madad se. Syntax: #Defining a function -step 1  def name(parameter1, parameter2,....parameterN):               Statement                return #Callling a function - step 2 name() Function ki jrurt kyo padi ? Function basically duplication of code ko reduce krta hai , jaise agar maan lo ki apko kuch block of code ki jrurt hai, aur usi program mai apko us block of code ki doobara jrurt hai , to apko baar baar wahi code d