How can I remove the final characters from a string in python until I reach a certain amount of characters?
How can I turn: abcdefghijklmnopqrstuvwxyz => abcdefghijklmnopqr; using python?
How can I remove the final characters from a string in python until I reach a certain amount of characters?
How can I turn: abcdefghijklmnopqrstuvwxyz => abcdefghijklmnopqr; using python?
Try string slicing.
You can use negative indexing:
'abcdefghijklmnopqrstuvwxyz'[:-8]
or positive:
'abcdefghijklmnopqrstuvwxyz'[:18]
Pick your poison
You can treat the string as an array of symbols
c_1 = "abcdefghijklmnopqrstuvwxyz"
l = 18
c_2 = c_2[:l]