Post History
If you print some string s without a newline character at the end, instead of print(s,end="") write print(end=s) to save two bytes. Note that this only works for strings, not for other typ...
Answer
#2: Post edited
- If you print some string `s` without a newline character at the end, instead of
- ```
- print(s,end="")
- ```
- write
- ```
- print(end=s)
- ```
- to save two bytes.
- Note that this only works for strings, not for other types.
- Note also that if you print more than one string, then the `end=` part will also prevent inserting spaces between them; to avoid getting those extra spaces, in that case you'll need to use string concatenation (string addition) instead.
- For example, instead of
- ```
- print(s,t,end="")
- ```
- use
- ```
print(end=s+t);- ```
- Again, this only works if all arguments are strings.
- If you print some string `s` without a newline character at the end, instead of
- ```
- print(s,end="")
- ```
- write
- ```
- print(end=s)
- ```
- to save two bytes.
- Note that this only works for strings, not for other types.
- Note also that if you print more than one string, then the `end=` part will also prevent inserting spaces between them; to avoid getting those extra spaces, in that case you'll need to use string concatenation (string addition) instead.
- For example, instead of
- ```
- print(s,t,end="")
- ```
- use
- ```
- print(end=s+t)
- ```
- Again, this only works if all arguments are strings.
#1: Initial revision
If you print some string `s` without a newline character at the end, instead of ``` print(s,end="") ``` write ``` print(end=s) ``` to save two bytes. Note that this only works for strings, not for other types. Note also that if you print more than one string, then the `end=` part will also prevent inserting spaces between them; to avoid getting those extra spaces, in that case you'll need to use string concatenation (string addition) instead. For example, instead of ``` print(s,t,end="") ``` use ``` print(end=s+t); ``` Again, this only works if all arguments are strings.