Post History
If you have a loop or if, you can save two or more characters (depending on the current indentation level and the number of statements in the body) by putting it right after the colon: For example...
Answer
#4: Post edited
- If you have a loop or `if`, you can save two or more characters (depending on the current indentation level and the number of statements in the body) by putting it right after the colon:
- For example, assume you have this loop with 33 characters:
- ```
- for x in a:
- do_something_with(x)
- ```
- Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 31 characters:
- ```
- for x in a:do_something_with(x)
- ```
- If the body has more than one statement, those can be separated with semicolon. For example
- ```
- if (condition):
- do_something()
- do_more()
- ```
- becomes
- ```
if condition: do_something();do_more()- ```
- Thanks to @Moshi for pointing out that it also works with several statements.
- If you have a loop or `if`, you can save two or more characters (depending on the current indentation level and the number of statements in the body) by putting it right after the colon:
- For example, assume you have this loop with 33 characters:
- ```
- for x in a:
- do_something_with(x)
- ```
- Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 31 characters:
- ```
- for x in a:do_something_with(x)
- ```
- If the body has more than one statement, those can be separated with semicolon. For example
- ```
- if (condition):
- do_something()
- do_more()
- ```
- becomes
- ```
- if condition:do_something();do_more()
- ```
- Thanks to @Moshi for pointing out that it also works with several statements.
#3: Post edited
If you have just one statement as body of a loop or `if`, you can save two or more characters (depending on the current indentation level) by putting it right after the colon:- For example, assume you have this loop with 33 characters:
- ```
- for x in a:
- do_something_with(x)
- ```
- Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 31 characters:
- ```
- for x in a:do_something_with(x)
- ```
- If you have a loop or `if`, you can save two or more characters (depending on the current indentation level and the number of statements in the body) by putting it right after the colon:
- For example, assume you have this loop with 33 characters:
- ```
- for x in a:
- do_something_with(x)
- ```
- Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 31 characters:
- ```
- for x in a:do_something_with(x)
- ```
- If the body has more than one statement, those can be separated with semicolon. For example
- ```
- if (condition):
- do_something()
- do_more()
- ```
- becomes
- ```
- if condition: do_something();do_more()
- ```
- Thanks to @Moshi for pointing out that it also works with several statements.
#2: Post edited
- If you have just one statement as body of a loop or `if`, you can save two or more characters (depending on the current indentation level) by putting it right after the colon:
For example, assume you have this loop with 34 characters:- ```
- for x in a:
do_something_with(x);- ```
Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 32 characters:- ```
for x in a:do_something_with(x);- ```
- If you have just one statement as body of a loop or `if`, you can save two or more characters (depending on the current indentation level) by putting it right after the colon:
- For example, assume you have this loop with 33 characters:
- ```
- for x in a:
- do_something_with(x)
- ```
- Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 31 characters:
- ```
- for x in a:do_something_with(x)
- ```
#1: Initial revision
If you have just one statement as body of a loop or `if`, you can save two or more characters (depending on the current indentation level) by putting it right after the colon: For example, assume you have this loop with 34 characters: ``` for x in a: do_something_with(x); ``` Since you've got just one statement, you can delete the newline character and the following indentation space, in order to get 32 characters: ``` for x in a:do_something_with(x); ```