Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python string indexing

str = 'codegrepper'
# str[start:end:step]
#by default: start = 0, end = len(str), step = 1
print(str[:]) 		#codegrepper
print(str[::]) 		#codegrepper
print(str[5:]) 		#repper
print(str[:8]) 		#codegrep
print(str[::2]) 	#cdgepr
print(str[2:8]) 	#degrep
print(str[2:8:2]) 	#dge
#step < 0 : reverse
print(str[::-1]) 	#reppergedoc
print(str[::-3]) 	#rpgo
# str[start:end:-1]	means start from the end, go backward and stop at start
print(str[8:3:-1]) 	#pperg
Comment

python index of string

string = "Hello World"
string_slice = string[1:10] # "ello Worl" (index 1 up to 10)
string_last_chars = string[-5:] # "World" (5th index from last to the end)
H = string[0] # "H"
Comment

Example of Python Strings with indexing

>>> x = "Follow us on Softhunt.net"
>>> x[0]
'F'
>>> x[1]
'o'
>>> x[6]
' '
>>> x[18]
'u'
>>> x[-1]
't'
>>> x[-25]
'F'
Comment

Python string index

kardiz = "Python"
kardiz[0]

'P'
Comment

PREVIOUS NEXT
Code Example
Python :: importing database in dataframe using sqlalchemy 
Python :: how to convert timestamp to date in python 
Python :: python obfuscator 
Python :: pandas check if column is sorted 
Python :: python list all methods of a class 
Python :: filter one dataframe by another 
Python :: lerp function 
Python :: python print datetime 
Python :: check if variable is of type decimal.Decimal python 
Python :: give a function a name python 
Python :: alpha beta pruning python code 
Python :: how to delete all instances of a model in django 
Python :: numpy remove columns containing nan 
Python :: access row of dataframe 
Python :: python loop go back to start 
Python :: python list of dictionaries to excel 
Python :: django pandas queryset 
Python :: [0] * 10 python 
Python :: python input integer only 
Python :: read a file with pandas 
Python :: execute terminal command from python 
Python :: how to downgrade python 3.9 to 3.8 
Python :: Remove empty strings from the list of strings 
Python :: create empty numpy array without shape 
Python :: python for character in string 
Python :: add column in spark dataframe 
Python :: create columns in streamlit 
Python :: how to pass parameters in python script 
Python :: python isset 
Python :: how to print a list of strings in python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =