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

  • Home
  • SEARCH
  • 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 7954785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:32:11+00:00 2026-06-04T03:32:11+00:00

def size(number): if number<100: return Small() if number<1000: return Medium() return Big() def size1(number):

  • 0
def size(number):
    if number<100:
        return Small()

    if number<1000:
        return Medium()

    return Big()

def size1(number):
    if number<100:
        return Small()
    elif number<1000:
        return Medium()
    else:
        return Big()

Regarding coding style:
I often use the former when the following blocks, or the last block is a large chunk of code. It seems to help readability.

I generally use the latter when the various blocks have a common concept running through them (as in the case above). The common indentation helps to communicate their relationship.

Are there any differences between these two worth noting (esp. performance wise)?

  • 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-04T03:32:13+00:00Added an answer on June 4, 2026 at 3:32 am

    Style-wise, I find the second example easier on the eye.

    In all other respects, there is no difference. The two functions compile to identical bytecodes:

    In [3]: dis.dis(size)
      2           0 LOAD_FAST                0 (number)
                  3 LOAD_CONST               1 (100)
                  6 COMPARE_OP               0 (<)
                  9 POP_JUMP_IF_FALSE       19
    
      3          12 LOAD_GLOBAL              0 (Small)
                 15 CALL_FUNCTION            0
                 18 RETURN_VALUE        
    
      5     >>   19 LOAD_FAST                0 (number)
                 22 LOAD_CONST               2 (1000)
                 25 COMPARE_OP               0 (<)
                 28 POP_JUMP_IF_FALSE       38
    
      6          31 LOAD_GLOBAL              1 (Medium)
                 34 CALL_FUNCTION            0
                 37 RETURN_VALUE        
    
      8     >>   38 LOAD_GLOBAL              2 (Big)
                 41 CALL_FUNCTION            0
                 44 RETURN_VALUE        
    
    In [4]: dis.dis(size1)
     11           0 LOAD_FAST                0 (number)
                  3 LOAD_CONST               1 (100)
                  6 COMPARE_OP               0 (<)
                  9 POP_JUMP_IF_FALSE       19
    
     12          12 LOAD_GLOBAL              0 (Small)
                 15 CALL_FUNCTION            0
                 18 RETURN_VALUE        
    
     13     >>   19 LOAD_FAST                0 (number)
                 22 LOAD_CONST               2 (1000)
                 25 COMPARE_OP               0 (<)
                 28 POP_JUMP_IF_FALSE       38
    
     14          31 LOAD_GLOBAL              1 (Medium)
                 34 CALL_FUNCTION            0
                 37 RETURN_VALUE        
    
     16     >>   38 LOAD_GLOBAL              2 (Big)
                 41 CALL_FUNCTION            0
                 44 RETURN_VALUE        
                 45 LOAD_CONST               0 (None)
                 48 RETURN_VALUE        
    

    (To be 100% accurate, the second version has an implicit return None at the end. However, since this code is not reachable, it won’t affect performance.)

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

Sidebar

Related Questions

class Ball: a = [] def __init__(self): pass def add(self,thing): self.a.append(thing) def size(self): print
asdf = [[1,2,3],[11,22,33,44,55,66],[51]] def recursive(params, index) if (index==params.size) puts DONE end currentParam = params[index]
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In
So the situation is like this. Suppose we have: class Test(datetime): def a(self): return
object NGram{ def main(args: Array[String]) { //args(0) = textfile //args(1) = size of n-grams
def tong_thoigian (self,kr,uid,ids,context={}): obj=self.browse(kr,uid,ids,context=context)[0] kr.execute('''select name,giolam from x_giolam where name=%s'''%(obj.ma_luong)) kq=kr.fetchall() tong=0.00000 for i
def __init__(self, maximum, start=0, step=1): Sets the maximum, start, and step try: self.maximum =
def foo (): x = re.compile('^abc') foo2(x) def foo2(x): How do I get x

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.