Python indexing and slicing

Python3 indexing and slicing

This lecture you will learn python indexing and slicing!


Indexing and slicing with strings
Indexing

Course = ‘Python for Beginners’
print(course[0])  // will prints 0 character i.e “P”  left to right
print(course[1])  // will prints 0 character i.e. “P”  left to right

print(course[-1]) // will prints the Last character i.e “s” Last character 

Note this facility is not available in other programming languages as well

print(course[-2]) // will prints the Last character i.e. “r” Last 2nd character 


Complete python course
All you need to know about standard and reserved keywords of python programming language, by type a keyword of formmowing command to you know your python version support reserved keywords.

Slicing:

print(course[0:3])  // python interpreter will identify from 0 to index 3 it will prints
Output : Pyt
print(course[:3]) // it will treated as starting index is 0
print(course[1:3])
print(course[:])  // complete string will print here // 0 would be assume and end of the string will be assumed
Let’s take one more variable 
more = course[:]     
Print (more)
Output: 
Python for Beginners

Exercise for you:
Name = ‘Python Student’
print(name[1:-1])
Tell me what is the Output of index printing 
The output is first Index starts from 2nd character and Second Index says that remove Last character the range of characters will be print here 
 Output is: ython Studen
For reverse string 
print(::-1)

  
Python data science interview questions and answers python is a high-level programming language using Data Science programs these days

Data Science

Harisystems is optimized for learning, testing and training. courses are designed to be simplified to improve reading and basic understanding for beginners to expert level. Tutorials and examples are constantly reviewed to avoid errors, however we cannot warrant full correctness of all content. if any found need to correct write us at info@harisystems.com. we Harisystems is not responsible for any with this tutorials, While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2007-2020 by Harisystems. All Rights Reserved.
Copyright © Harisystems 2020