Python Forum
Python OOP - two numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python OOP - two numbers
#31
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.
ben1122 likes this post
Reply
#32
(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 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,426 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,011 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,107 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020