Python Field Calculator Equivalent [:] of Right( ) or Left( ) in VB Field Calculator

7358
1
01-06-2011 09:33 AM
DanielSheehan
New Contributor II
I'm starting to use Python in the Field Calculator and I just found this out after an hour or so of frustration using rstrip() and rsplit() realized its even easier though not as obvious.

So lets say I wanted to remove the leading character of a 8 digit string in my [UID] field

In VB I'd say:

Right([UID], 7)

In Python I'm saying

!UID![1:]

You may put numbers after the colon [1:4] as well to manipulate the return string lengths and where the string is pulling those lengths from, other than that I don't know but it may help if someone knows the name of this function - if so please comment below?
Tags (2)
0 Kudos
1 Reply
ZoeZaloudek
Occasional Contributor
It's called a "slice" (I think it's because you are slicing the string, like cutting a stick of butter in half with a knife).  Anyway, here's a link to a page that explains more about it and shows examples:

http://docs.python.org/tutorial/introduction.html#strings

You'll have to scroll about halfway down the page to get to the parts about slicing.
0 Kudos