Interesting Cool Python Tricks for working with Strings
“Python tricks” is a tough one, cuz the language is so clean.
Python programming language is one of the popular programming languages among many new and old programmers. It provides a easy to read and a pseudo-code format of program. This helps in easy understanding of the overall program structure and algorithm.
There are many ways in, which a particular python logic can be written. Below are some of the cool Python program tricks, which might help you to work with strings. Use the below tricks and get your logic working easier.
Strings
Let us see the different operations that can be performed on the below string.
word = 'Sample'
len(word)
Output
6 +---+---+---+---+---+---+
| S | a | m | p | l | e |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1
#1 Concatenation
Join a string with another string
word = 'Sample'
word + ' ' + 'trick'
Output
'Sample trick'
#2 Indexed Access of Strings
A string in a python can be indexed to perform operations on the string