DAY 3 - Strings

PythonStrings hashtagPython doesn't support character type. so a single letter will be treated as a string of length - 1 and index starts from 0. val ="He is a good guy." val1 = 'She is a good gal.' > val[-1] # '.' > val1[1] #'h' > val1[1:] # 'he is a good gal.' > val[1:4] # 'e i' > number = '123456789' > even_number = number [1: :2] # '2468' hashtagpick every alternate digit from index = 1 > odd_number = number [0: :2] # '13579' hashtagpick every alternate digit from index = 0 > Sibling = 'RAKESH_RUPESH_RITESH_PUJA' > first_Sibling,second_Sibling,third_Sibling,fourth_Sibling = Sibling.split('_') # 'RAKESH' 'RUPESH' 'RITESH' 'PUJA' > 'PUJA' in Sibling hashtagTrue > first_Sibling * 2 # 'RAKESHRAKESH' # multiply sequence by integer only > first_Sibling + second_Sibling # 'RAKESHRUPESH' # can only concatenate str (not "int") to str hashtagreplace() > val.replace('He','She') #'She is a good guy.' > Sibling.replace('R','P',2) # 'PAKESH_PUPESH_RITESH_PUJA' hashtagreplaced only 2 occurrences of R hashtagupper() lower() capitalize() > val.upper() # 'HE IS A GOOD GUY.' > Sibling.lower() # 'rakesh_rupesh_ritesh_puja' > 'he is A Good Guy'.capitalize() # 'He is a good guy' hashtagRR hashtagDay3 hashtagPython hashtagStrings hashtagDataScience hashtagHappyLearning hashtagWeLearnEveryday

Comments

Popular posts from this blog

Day 32 - Python Script to track Available COVID-19 Vaccine Slots for 18+ in India

DAY 1 - Steps to prepare your windows laptop for Python Programming

Day 26 - Call Power BI REST APIs to get POWER BI REPORT Details