Define the term String Slicing with suitable example
Answers
Answered by
18
Answer:
ᴘʏᴛʜᴏɴ sʟɪᴄɪɴɢ ɪs ᴀʙᴏᴜᴛ ᴏʙᴛᴀɪɴɪɴɢ ᴀ sᴜʙ-sᴛʀɪɴɢ ғʀᴏᴍ ᴛʜᴇ ɢɪᴠᴇɴ sᴛʀɪɴɢ ʙʏ sʟɪᴄɪɴɢ ɪᴛ ʀᴇsᴘᴇᴄᴛɪᴠᴇʟʏ ғʀᴏᴍ sᴛᴀʀᴛ ᴛᴏ ᴇɴᴅ.
ᴘʏᴛʜᴏɴ sʟɪᴄɪɴɢ ᴄᴀɴ ʙᴇ ᴅᴏɴᴇ ɪɴ ᴛᴡᴏ ᴡᴀʏs.
- sʟɪᴄᴇ() ᴄᴏɴsᴛʀᴜᴄᴛᴏʀ
- ᴇxᴛᴇɴᴅɪɴɢ ɪɴᴅᴇxɪɴɢ
ᴇxᴀᴍᴘʟᴇ:
# ᴘʏᴛʜᴏɴ ᴘʀᴏɢʀᴀᴍ ᴛᴏ ᴅᴇᴍᴏɴsᴛʀᴀᴛᴇ
# sᴛʀɪɴɢ sʟɪᴄɪɴɢ
# sᴛʀɪɴɢ sʟɪᴄɪɴɢ
sᴛʀɪɴɢ ='ᴀsᴛʀɪɴɢ'
# ᴜsɪɴɢ sʟɪᴄᴇ ᴄᴏɴsᴛʀᴜᴄᴛᴏʀ
s = sʟɪᴄᴇ()
s = sʟɪᴄᴇ(, , )
s = sʟɪᴄᴇ(-, -, -)
ᴘʀɪɴᴛ("sᴛʀɪɴɢ sʟɪᴄɪɴɢ")
ᴘʀɪɴᴛ(sᴛʀɪɴɢ[s])
ᴘʀɪɴᴛ(sᴛʀɪɴɢ[s])
ᴘʀɪɴᴛ(sᴛʀɪɴɢ[s])
Similar questions