Printing loop statement ?

13 views
Skip to first unread message

Christopher.

unread,
Jun 1, 2015, 11:52:58 PM6/1/15
to python_in...@googlegroups.com
You can print a loop, one thing I don't understand is the following;
Suppose I have 

for j in range (0,5):
First thing, what is the string 'j=' + str(j)) doing, I know what the second part of the loop is doing, converting the variable into a string or rather the float into a string, what is the first half of the statement saying ?

Geordie Martinez

unread,
Jun 1, 2015, 11:56:55 PM6/1/15
to python_inside_maya
it's just a string and the plus sign is tacking the other string to the end of it. concatenating.
there are a lot of ways to concatenate strings in python.

another popular way is called "string formatting". you can find some decent examples here:
http://www.diveintopython.net/native_data_types/formatting_strings.html

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1b6d806a-80e1-485e-96c5-525136bdb599%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Geordie Martinez

unread,
Jun 2, 2015, 12:06:34 AM6/2/15
to python_inside_maya
you probably have something like this I'm guessing:


for j in range(0,5):
    print('j=' + str(j)) # print the value of j for testing
    # with string formatting.
    print("string formatted: j=%s" % j)

Christopher.

unread,
Jun 2, 2015, 12:22:42 AM6/2/15
to python_in...@googlegroups.com
I deleted the tab; argh, I don't think it included the last line in your loop, it was strictly for the history panel to tell me how each object was being manipulated.  


On Tuesday, June 2, 2015 at 12:06:34 AM UTC-4, Geordie Martinez wrote:
you probably have something like this I'm guessing:


for j in range(0,5):
    print('j=' + str(j)) # print the value of j for testing
    # with string formatting.
    print("string formatted: j=%s" % j)
On Mon, Jun 1, 2015 at 8:56 PM, Geordie Martinez <geordie...@gmail.com> wrote:
it's just a string and the plus sign is tacking the other string to the end of it. concatenating.
there are a lot of ways to concatenate strings in python.

another popular way is called "string formatting". you can find some decent examples here:
http://www.diveintopython.net/native_data_types/formatting_strings.html
On Mon, Jun 1, 2015 at 8:52 PM, Christopher. <crestchr...@gmail.com> wrote:
You can print a loop, one thing I don't understand is the following;
Suppose I have 

for j in range (0,5):
First thing, what is the string 'j=' + str(j)) doing, I know what the second part of the loop is doing, converting the variable into a string or rather the float into a string, what is the first half of the statement saying ?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages