Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:05:07+00:00 2026-06-10T06:05:07+00:00

Friday I had a discussion with someone about the following contruction: class C(…. c

  • 0

Friday I had a discussion with someone about the following contruction:

class C(....

c = C()
d = C()
...

(c if some_boolean else d).some_function_of_class_C()

Is this kind of if statement acceptable/encouraged?

The problem is that a lot of people I work with have C experience but not that much Python experience and are not used to such statement (same like list comprehension).
However, Python is not C and I think the advantages of the Python language should be used.
Or not?

(btw, I use normal function names and variable names but it is just for the sake of this example to keep it sample. Also I do not only call f() but some more functions (like f().g() which I woud have to repeat completely in that case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:05:09+00:00Added an answer on June 10, 2026 at 6:05 am

    There’s nothing technically wrong with your code, but it is a little odd and surprising to see code like that.

    Splitting your statement into two separate statements improves the readability:

    c = c1 if some_boolean else c2
    c.some_function_of_class_C()
    

    The terrible variable names you have chosen still make it look awful. But changing the variable names also helps to improve the readability:

    vehicle = plane if distance > 1000 else car
    vehicle.travel()
    

    That is a lot more readable than what you originally proposed, in my opinion, and it only took a very small change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I had fixed this on Friday through a type correction, but I
Let's say I had a string like this: string source = Today is friday!
Hope everyone is enjoying this wonderful Aloha Friday, I have a question about HTML
I have spent all Friday and Saturday on this and I am running out
How can you calculate the following Friday at 3am as a datetime object? Clarification:
It's late on a Friday and I'm scratching my head on this one. I'm
This is probably going to be more of a discussion or hypothetical question, but
I had a problem with date manipulation.This is my scenario.I have a daily generating
After last Friday's announcement, I'm just getting around to reading about the Silverlight 3
Ok, it's friday afternoon, and i've had a long week so would appreciate some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.