Python Forum

Full Version: Python OOP - two numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
When the PEP talks about multiple statements on one line it means code like this:
squares = []; cubes = []
for x in range(10): squares.append(x**2); cubes.append(x**3)
print(squares); print(cubes)
Each line has multiple expressions. The PEP is not condemning list comprehensions or a conditional expressions/ternary operators. A list comprehension is a single statement. Maybe a complex looking statement, but still a single statement/expression. Once you get comfortable using them you'll find yourself seeking opportunities to use them.
(Oct-01-2021, 07:44 PM)deanhystad Wrote: [ -> ]When the PEP talks about multiple statements on one line it means code like this:
squares = []; cubes = []
for x in range(10): squares.append(x**2); cubes.append(x**3)
print(squares); print(cubes)
Each line has multiple expressions. The PEP is not condemning list comprehensions or a conditional expressions/ternary operators. A list comprehension is a single statement. Maybe a complex looking statement, but still a single statement/expression. Once you get comfortable using them you'll find yourself seeking opportunities to use them.

Oh I didnt talk about the list comprehension, the first thing.
But it doesnt matter, I prefer less doing list comprehension, maybe in the future when I will get better at python.
Thanks :)
Pages: 1 2 3 4