Skip to main content

Posts

Showing posts from March, 2021

Python Language Basics - 2

Slice string in python: details= "Akshay Kumar Gupta--akshaygupta.me" # details[:6] and details[0:6] will give same result print(details[: 6 ]) # OUTPUT: Akshay # details[20:] and details[20:34] will give same result print(details[ 20 :]) # OUTPUT: akshaygupta.me # -1 denotes the reverse order print(details[ 11 ::- 1 ]) #OUTPUT: ramuK yahskA # Here -9 denotes the count from the end of the string print(details[:- 9 :- 1 ]) #OUTPUT: em.atpug #Both syntax gives the same result for reversing the string print(details[- 1 ::- 1 ]) #OUTPUT: em.atpugyahska--atpuG ramuK yahskA print(details[::- 1 ]) #OUTPUT: em.atpugyahska--atpuG ramuK yahskA Format print in python: print( "hi, My name is {} and I am a {}. I like {}." .format( "Akshay" , "Software Engineer" , "python" )) In the above print statement, "{}" refers to the placement of the values given in "format()" function. First value in the order "format()"