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 :: save mdoel summary python 
Python :: python finding mead 
Python :: how to decide that the input must be a integer less than 5 in python 
Python :: remap values in a column based on condition from another dataframe 
Python :: lime python interpretation 
Python :: merge sort dictionary python 
Python :: using format str with variable 
Python :: unique lits on python 
Python :: python how to do imports 
Python :: vorticity 
Python :: python sumproduct excel 
Python :: difference between iglob() and glob() functions in python 
Python :: how to dinamically create the Q query in django 
Python :: Python NumPy broadcast_arrays() Function Syntax 
Python :: Python NumPy Shape function example Printing the shape of the multidimensional array 
Python :: python text file contains 
Python :: Python NumPy asmatrix Function Syntax 
Python :: Python NumPy dstack Function Example 02 
Python :: Python NumPy delete Function Example Deletion performed using Boolean Mask 
Python :: retinaface detection 
Python :: python model feature importance 
Python :: godot knockback 
Python :: pymenu template 
Python :: #check if the given date is a weekday or weekend 
Python :: geopandas gdf or df to file 
Python :: python dependency injection 
Python :: python how do I count the time that it takes for the sorting to execute in seconds? [closed] 
Python :: how to make a yes or no question in python 
Python :: Which of the following is not a core data type in Python programming? 
Python :: singke line expresions python 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =