What does end exactly do

0 votes

So, I'm struggling trying to understand this kinda simple exercise

def a(n):
    for i in range(n):
        for j in range(n):
            if i == 0 or i == n-1 or j == 0 or j == n-1:
                print('*',end='')
            else:
                print(' ',end='')
        print()

which prints an empty square. I tought I could use the code

            print("*", ''*(n-2),"*")

to print the units in between the upper and the lower side of the square but they won't be aligned to the upper/lower side ones, which doesn't happen if you run the first code... so... could this be because of end='' or print() (would you be so kind and tell me what do they mean?)?

May 2, 2022 in Python by Edureka
• 13,620 points

edited Mar 4 125 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP