Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

john larson
16,594 PointsI saw this syntax on a python practice website. I was wondering if this is frowned upon
The code to execute follows the conditional on the same line. It works fine, but I was wondering if it's one of those things that just isn't done.
def move_player(player, move):
x,y = player
if move == "L":
if x == 0:print("That's a wall")
else:x -=1
if move == "R":
if x == 4:print("That's a wall")
else:x +=1
if move == "U":
if y == 0:print("That's a wall")
else:y-=1
if move == "D":
if y == 4:print("That's a wall")
else:y+=1
return x,y
1 Answer

doesitmatter
12,885 PointsGo to: PEP 8
Scroll a bit down to where it says:
Compound statements (multiple statements on the same line) are generally discouraged.
You will find that it is not recommended with examples and such.