Python Forum
Use range to add char. to empty string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use range to add char. to empty string
#1
This seems simple enough, but I can't seem to get my head around it.

The problem:
Create an empty string and assign it to the variable lett. Then using range, write code such that when your code is run, lett has 7 b’s ("bbbbbbb").

My attempt:
lett = ' '
for _ in range (7):
     append.lett(b)
print(lett)
I'm pretty sure you can't append to a string, but I'm at a loss for other options. It doesn't seem like we can split lett then rejoin.
Reply


Messages In This Thread
Use range to add char. to empty string - by johneven - Apr-15-2019, 09:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with stripping special char and spaces mumstead 7 2,817 Jun-11-2020, 05:44 AM
Last Post: Yoriz
  String index out of range felie04 2 5,581 Aug-17-2018, 11:18 PM
Last Post: felie04
  string index out of range cusick11 9 15,205 Mar-03-2017, 11:45 PM
Last Post: ichabod801
  Invalid syntax: string index out of range darkreaper1959 6 6,216 Jan-22-2017, 06:24 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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