# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# str
s="Hello"
print(s)
print(id(s))

s="Hello111"
print(s)
print(id(s))

s="""Hello"""
print(s)
print(id(s))
# -

#string slicing
str="helloworld"
print("first character:",str[0])
print("0 to upto 2 index:",str[:3])
print("1 to 4rth:",str[1:5])
print("2nd upto -3:", str[2:-2])

# +
#string membership 
str= "helloWorld"
if "q" in str:
    print("present")
else:
    print("not present")

if "W" not in str:
    print("not present")
else:
    print("present")

# +
#strip the trailing and leading spaces
s="Hello World "
print("length: ", len(s))
print("strip:", s.strip())

s="hello,world,tannu"
print("length after striping:", len(s.strip()))

#split
print("split the s:", s.split(","))
#split upto 1 string=> 2 strings will be generated 
print("split:", s.split(",",1))

#count the number of occurences in the string
s="hello world"
print("no of occurences:", s.count("l"))
print("no of occ from 0 to 5:", s.count("l",0,5))
# -

#find character and return the first occurence(match) index from 0to len-1
str="HelloWrold"
print("found or not:", s.find("l",0,len(str)))

# +
#without slicing, reverse
s=input("enter the string:")
rev=""
l=len(s)
i=l-1
while i>=0:
    rev+=s[i]
    i-=1

print(rev)


# -

#using slicing
s=input("input:")
print(s[::-1])




StarcoderdataJupyterScriptsDedupFiltered