0% found this document useful (0 votes)
53 views2 pages

Practical 0.1 PDF

This document discusses various string methods and operations in Python like string indexing, slicing, formatting, methods like upper(), lower(), title(), count(), find(), replace() etc. It also discusses basic conditional statements like if-else and taking multiple inputs in a single line. Examples are provided to demonstrate each concept.

Uploaded by

Shanu Prakash
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)
53 views2 pages

Practical 0.1 PDF

This document discusses various string methods and operations in Python like string indexing, slicing, formatting, methods like upper(), lower(), title(), count(), find(), replace() etc. It also discusses basic conditional statements like if-else and taking multiple inputs in a single line. Examples are provided to demonstrate each concept.

Uploaded by

Shanu Prakash
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/ 2

2/29/2020 Untitled3

In [3]:

# String Reverse

name = "python"
print (name[::-1])

nohtyp

In [33]:

# String Medhods
name= "This is String Method"

print(f"Lengta of string is {len(name)}" ) # length of the string / String formating


in python 3.6
print("String in lower charactor is : {} ".format(name.lower())) # string convert in lo
wer character / String formating in python 3
print(name.upper() ) # string cahnge in upper character
print(name.title()) # first character of each word in capital
print(f"The char i in the string is {name.count('i')} times ") # the no of i in the s
tring

Lengta of string is 21
String in lower charactor is : this is string method
THIS IS STRING METHOD
This Is String Method
The char i in the string is 3 times

In [27]:

# String Indexing
name= "python"
print(f"The first char is {name[0]}") #print first char
print(f"The Fourth char is {name[3]}") #print 4th char
print(f"The first four char is {name[0:4]}") # print from 0 index to 3rd index
print(f"at interval of 2 is {name[0:6:2]}") # print from 0 to 5th index with step of tw
o

The first char is p


The Fourth char is h
The first four char is pyth
at interval of 2 is pto

In [28]:

# Reverse of a string
name = "python"
print(name[-1::-1])

nohtyp

localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 1/2
2/29/2020 Untitled3

In [31]:

# multiple input in single line'


name , age = input("enter the name and age saperated by , :").split(",")
print(f"The name is {name} and the age is {age}")

enter the name and age saperated by , :python,25


The name is python and the age is 25

In [36]:

# find() & replace()


string="Hellow how are you dear are you feeling well"
print(string.replace(" ","_")) # replace " " space with _
print(f'Position of are1 is : {string.find("are")} ') # find the position of are in the
string
position_of_are1= string.find("are") #position of are1
print(f"Position of are2 is : {string.find('are',position_of_are1 +1)}") # position of
are2

Hellow_how_are_you_dear_are_you_feeling_well
Position of are1 is : 11
Position of are2 is : 24

In [38]:

# If Else Statement
#syntex - if {this}:
age= int(input("Enter your age")) #user input in intiger
if age>=18: # if statement
print('You are a adult') #if statement true the this code will exicute
else:
print('You are under 18') #if statement is false this code will exicute

Enter your age20


You are a adult

In [ ]:

localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 2/2

You might also like