Skip to content

#Pi #11410

@Vibemonk

Description

@Vibemonk

#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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions