An example would be
abc:def:ghi:jkl
How would I code in python to make it so that only abc is printed?
I know I’d start with
String =”abc:def:ghi:jkl”
But I’m not sure whats next
Sorry, I’m new to python and regex…
New contributor
Linda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Regex isn’t needed. Split the string. Get the first element of the list.
s = 'abc:def:ghi:jkl'
first = s.split(':')[0]
print(first)