Guided Project: Investigating Fandango Movie Ratings - Comparing Relative Frequencie

Screen Link: https://github.com/dataquestio/solutions/blob/master/Mission288Solutions.ipynb

Hi there
In the solution notebook of Guided Project: Investigating Fandango Movie Ratings while performing < Comparing Relative Frequencies> the code used in the solution book is ------- print(‘2015’ + ‘\n’ + ‘-’ * 16)
I didn’t get the exact idea of this pattern is there any other alternative or can anyone just explain to me why this pattern was taken. I am confused with this.

Just to add specific formatting.

'2015' - Prints out 2015

'\n' - Prints out a newline character. That’s essentially a new blank line is printed below the “2015” printed value. You can read on some of these string literals here.

'-' * 16 - This basically says “print “-” 16 times”.

In Python, you can perform arithmetic operations like + or * on strings. The result is that + will concatenate two strings, and * will create that many copies of that string.

So, '-' * 16 ends up printing out -

----------------

1 Like