0% found this document useful (0 votes)
6 views3 pages

Python String Operations Guide

Uploaded by

shraddhavinod1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python String Operations Guide

Uploaded by

shraddhavinod1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#string

str1="My name is Ankita. \nCOllege name is ccs. \nClass is sybca"

print(str1)

#basic operation

# 1)concatination +

str1="Hello"

str2="World"

print(str1+str2)

#2) Length of string len(str)

str1="Hello"

len1=len(str1)

print(len1)

str2="Hello World"

len2=len(str2)

print(len2)

#indexing start from 0

str1="College Wakad"

ch=str1[4]

print(ch)

print(str1[7])

#string Slicing = Accessing part of a string

# str[starting_idx : ending_idx] ending index is not included

str="COllege Wakad"
print(str[1:5])

print(str[0:6])

print(str[8:12])

print(str[5:])

print(str[:10]) #[0,10]

#Negative Indexing

str="College" # -6,-5,-4,-3,-2,-1,0

print(str[-5:-1]) #output lleg

print(str[-6:-3]) #output oll

#String Function

#1) endswith function

str="I am learning python"

print([Link]("on")) #True

print([Link]("learn")) #False

# 2) capitalize -> 1st leter capital

str="college ccs wakad"

print([Link]())

# 3) replace ->(old,new)

str="College ccs wakad"

print([Link]("wakad","Pune"))

print([Link]("c","n"))

# 4) find() -> first time

str="College ccs wakad"


print([Link]("e")) #4

print([Link]("ccs")) #8

# 5) count() -> count

str="Hello world Hello Sybca student Hello tybca welcome"

print([Link]("Hello")) #3

print([Link]("l")) #8

#Practice questions

#wap to input users first name and print its length

name=(input("Enter your name"))

print(len(name)) # Shruti=6

You might also like