Python for Visual Basic or C# programmers

Metalone jcb at iteris.com
Thu Jun 1 14:03:01 EDT 2006


A.M wrote:
> Hi,
>
>
>
> I am trying to find the equivalent functions  such as vb's str or asc in
> Python. Is there any resource that help me to find these kinds of functions
> in Python faster?
>
>
>
> Thank you,
>
> Alan

>
> Alan

Python has a str() function that is close to vb's str.  The Python
version does not produce a leading space.
str(123) --> '123'

If you want to control the formatting to mimick vb or create different
formatting you can use.
" %d" % 123 --> ' 123'
The format specifier is just like 'C's printf format strings.
A tuple should follow the % sign if formatting more than 1 number.
"%d %d" % (123, 456)

Python has a similar function to vb's asc.
It is ord().
ord() accepts a single character, whereas asc operates on the first
character of a string.
To mimick vb you could do
s = 'hello'
ord(s[0]) --> 104

I am unaware of any reference associating vb functionality with Python
functionality.
Then again, I never looked for one.




More information about the Python-list mailing list