<jupyter_start><jupyter_text>2.Strings---  Find the length of the given string<jupyter_code>country = 'Nepal'
country
len(country)
country = 'नेपाल'
country
len(country)
country = input("Enter name of a country:")
len(country)<jupyter_output><empty_output><jupyter_text>Find half of a given string<jupyter_code>country = 'Bhutan'
country[0:3]<jupyter_output><empty_output><jupyter_text>*__String[start:end]__, where, __start__ is inclusive and __end__ is exclusive*<jupyter_code>country[3:6]
country[:3]<jupyter_output><empty_output><jupyter_text>*__0__ is default for __start__, and __len__ is default for __end__*<jupyter_code>len(country)
country[3:]
country = input("Enter name of a country:")
half = len(country)//2
print(country[:half])
print(country[half:])
country[:2.5]<jupyter_output><empty_output><jupyter_text>What is last character of given country<jupyter_code>country
country[len(country) - 1]
# second last character
country[len(country) - 2]
# using shortcut find third last character
country[-3]
country[-1]<jupyter_output><empty_output><jupyter_text>Find every second characters from a given string<jupyter_code>country
country[:]
country[::]<jupyter_output><empty_output><jupyter_text>*__string[start:end:step]__, where __step__ is optional and __1__ is default value.*<jupyter_code>country[::2]
country[1::2]<jupyter_output><empty_output><jupyter_text>Find first three characters using negative index/slicing<jupyter_code>country
country[:3]
country[-7:-4]
country[:-4]<jupyter_output><empty_output><jupyter_text>*selection from left to right*  Reverse a given string<jupyter_code>country[::-1]<jupyter_output><empty_output><jupyter_text>**H/W: Find out default for start and end when step is negative.**<jupyter_code># find first 3 characters reversed of string using negative step
country[-5::-1]<jupyter_output><empty_output><jupyter_text>Split given paragraph into words<jupyter_code>example = '''This black cockatoo has a short crest, mostly greyish-black plumage, 
prominent white cheek patches, and a white tail band. '''
example.split()
example.split(',')<jupyter_output><empty_output><jupyter_text>*Return result is __list__ type, denoted by __[__ __]__* **H/W**  Show all characters of the word<jupyter_code>word = input("Enter a word: ")
for char in word:
    print("The {}th character of word is: {}".format(word.index(char), char))
print("This is end")<jupyter_output>The 0th character of word is: w
The 1th character of word is: h
The 2th character of word is: i
The 3th character of word is: t
The 4th character of word is: e
This is end<jupyter_text>__for__ means go through each character one by one, and put each character to name __char__.*This technique of cycling through using __for__ is called looping**Note: Don't forget to put "__:__" at the end of __for__ line, and remember to start __print__ below, 4 spaces from left.*  How many words are there in a paragraph ?<jupyter_code>paragraph = '''
My country Nepal is surrounding by two countries. China lies in the east side and west, north and south is cover by India. 
It is in the northern hemisphere. It has three geographical zones. Himalayan, Mountainous and tarai. 
We have monsoon climate. It is very cold and dry in winter and hot, stormy and rainy in summer. 
It is rich in natural beauty and resources. It has long and wide rivers like koshi, Gandaki, and Karnali. 
We have large lakes like Rupa, Begnas, and Rara etc. like-wise we have green valleys, lovely water falls etc.  
It is rich in religious and historical heritages. Lumbini, Gorkha, Janakpur, Kathmandu are the famous examples.
'''
words_count = 0
for c in paragraph.split():
    words_count += 1
print("Total number of words = {}".format(words_count))<jupyter_output>Total number of words = 111
{'fraction_non_alphanumeric': 0.10127591706539076, 'fraction_numerical': 0.010101010101010102, 'mean_word_length': 6.49601593625498, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '330437', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1200, 'n_words': 413, 'path': 'Sessions/2.Strings.ipynb', 'repo_name': 'Yunika-Bajracharya/pybasics', 'size': '3762'}