-
-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Closed as not planned
Description
#string slicing - used to create a substring by extracting elements from another string
#indexing [] and slice ()
#[strat:stop:step]
name = "Yash tiwari"
first_name = name[0]
first_name = name[0:2]
first_name = name [0:5]
print(first_name)
last_name = name[5:11]
print(last_name)
#step is an optional field to which we can set a value to.
first_name = name[:4]
last_name = name[4:]
funky_name = name [::2]
print(funky_name)
reverced_name = name [::-1]
print(reverced_name)
#slicing () slice
website = "http:// google.com"
slice = slice(7,-4)
print(website[slice])
Metadata
Metadata
Assignees
Labels
No labels