Python Forum
Don't understand example code from a textbook
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't understand example code from a textbook
#1
I'm just starting to learn python and I'm using a textbook to learn. For demonstrating for loops the book used this bit of code:

print('My name is')
for i in range(5):
 print('Jimmy Five Times (' + str(i) + ')')
I understand it for the most part except for the + operators in front of and behind of str(i). I know what they are, but for some reason I'm having a hard time figuring out why they are both needed in that bit of code. The textbook isn't explaining it.
buran write Jan-25-2021, 06:50 PM:
OP figured it out and removed the text, but i restored the original content
buran write Jan-25-2021, 06:49 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
string + string in Python, is string concatenation. ie: two strings separated by a plus sign are combined into a new string.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 314 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Unable to understand how given code takes a fixed input value, without inputting. jahuja73 4 2,714 Jan-28-2021, 05:22 PM
Last Post: snippsat
  Unable to understand a statement in an existing code ateestructural 1 2,238 Aug-01-2020, 09:38 PM
Last Post: deanhystad
  Is Python useful for creating a textbook? iwue897s 1 1,631 Jun-21-2020, 06:20 AM
Last Post: DPaul
  Trying to understand the python code spalisetty 2 1,882 Mar-16-2020, 08:11 AM
Last Post: javiertzr01
  I couldn't understand the output of the below code ravich129 1 1,938 Dec-12-2019, 06:24 AM
Last Post: sandeep_ganga
  can you understand why this code prints None? arcbal 2 2,770 Mar-13-2019, 02:57 AM
Last Post: arcbal
  Can someone help me please understand this code? Jayboii478 2 3,374 Mar-02-2019, 07:26 PM
Last Post: seco
  Don't understand why this quicksort code works lupoalberto 6 4,019 Mar-27-2018, 10:01 AM
Last Post: lupoalberto
  Can't understand the code SelectiveDuplicate 2 2,941 Mar-23-2018, 07:57 AM
Last Post: SelectiveDuplicate

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020