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

Python Programming 3

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)
0 views3 pages

Python Programming 3

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
You are on page 1/ 3

#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(str.endswith("on")) #True

print(str.endswith("learn")) #False

# 2) capitalize -> 1st leter capital

str="college ccs wakad"

print(str.capitalize())

# 3) replace ->(old,new)

str="College ccs wakad"

print(str.replace("wakad","Pune"))

print(str.replace("c","n"))

# 4) find() -> first time

str="College ccs wakad"


print(str.find("e")) #4

print(str.find("ccs")) #8

# 5) count() -> count

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

print(str.count("Hello")) #3

print(str.count("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