Instead of having multiple calls to input, this can be very useful. Especially handy when parsing multiple lines
x=open(0).read()
Can be used with .split() and tuple unpacking too:
a,b,*m,e=map(int,open(0).read().split())
Note that here both a and b would be evaluated.
x=a if c else b
x=[b,a][c] # -5 chars
Only really works for strings that are the same length
x=["hello","there","world"][c]
x="htweholerlrloed"[c::3]
input() to print final statement and exitIf the last thing you are doing in your program is print(x), it can be replaced with input(x). This will cause an IO Exception, nevertheless the output will still be printed before the program crashes. For most places this output is counted as valid.
A few reasons this would be helpful:
input() calls, using I=input can save chars if you also use I() to print.if a:print(x)
else:print(y)
# becomes
if a:input(x)
input(y) # if `a` is True, won't get here if there's no more in
for loopsIf the loops is simple and you don't actually care about the indices, you can do the following:
for i in range(5):_
for i in "."*5:_ # -3 chars
exec("_;"*5) # -7 chars