Jul-28-2019, 06:40 PM
1) end=''
What happens if you run the print() function?
There is nothing inside the parenthesis, so you tell python to print nothing
but actually something happens on the screen.
Yeah the cursor is going one line down because you print a "Carriage return/New line" character
and this is due to the default parameter end='\n'.
Just run help(print).
So overriding this default by explicitly calling the print function with end=''
you suppress the "going to the next line" and the cursor stays behind your last output.
2) print('Name:{} Street:{} Town:{}'.format(name, street, town))
The .format() is used to conveniently insert the value of variables into a string.
You could see it as a type of concatenation.
You could code it as print('Name:', name, 'Street:', street, 'Town:', town)
Since Python 3.6 there are so-called f-strings which is an even more convenient type of
string formatting.
It would look like print(f'Name:{name} Street:{street} Town:{town}')
where in all examples name, street and town are variables.
I hope that helps you understand it.
What happens if you run the print() function?
There is nothing inside the parenthesis, so you tell python to print nothing
but actually something happens on the screen.
Yeah the cursor is going one line down because you print a "Carriage return/New line" character
and this is due to the default parameter end='\n'.
Just run help(print).
So overriding this default by explicitly calling the print function with end=''
you suppress the "going to the next line" and the cursor stays behind your last output.
2) print('Name:{} Street:{} Town:{}'.format(name, street, town))
The .format() is used to conveniently insert the value of variables into a string.
You could see it as a type of concatenation.
You could code it as print('Name:', name, 'Street:', street, 'Town:', town)
Since Python 3.6 there are so-called f-strings which is an even more convenient type of
string formatting.
It would look like print(f'Name:{name} Street:{street} Town:{town}')
where in all examples name, street and town are variables.
I hope that helps you understand it.