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 6579965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:57:52+00:00 2026-05-25T15:57:52+00:00

I’m trying to learn Python from a background in javascript. I saw someone make

  • 0

I’m trying to learn Python from a background in javascript. I saw someone make a recursive function to find the least common denominator and wondered why they didn’t just use a loop, so, both for the experience and to amuse myself, I wrote a simpler one:

I came up with:

def LCM(n,d):
    while(n%d++ != 0 ):
        continue
    return d-1
print(LCM(99,12))

Needless to say, for those of you that know Python, ++ isn’t a valid operator. I also tried

def LCM(n,d):
    while(n%(d+=1) != 0 ):
        continue
    return d-1
print(LCM(99,12))

To make sure it wasn’t my thinking that was off, I tried the same thing in javascript:

function LCM(b,d){
   while(b%d++ != 0){
   }
return d-1;
}

So does Python not allow expressions like in javascript? Also, is indentation the only way to define something? I know semicolons aren’t required but can be used, is there anything like that in terms of closing a loop or function definition?

Finally, are is and is not the Python equality-without-type-coersion operator?

P.S. I realize the function isn’t practical without checking the input for various things, but that wasn’t the point in writing it.

P.P.S Also, is there a Python equivalent of the javascript evaluation ? on true : on false if statement abbreviation?

  • 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-05-25T15:57:52+00:00Added an answer on May 25, 2026 at 3:57 pm

    Python does not allow assignments (such as i+=1) in expressions since those can lead to confusing code, and Python is designed to make it hard to write confusing code, and make it simple to write obvious code.

    You can simply write this:

    def LCM(n,d):
        while n%d != 0:
            d += 1
        return d-1
    print(LCM(99,12))
    

    Python’s is tests for two objects being the same object instead of just equal. Consider the following:

    d = {}
    e = d
    assert d == {}     # Empty dictionaries equal each other
    assert d is not {} # .. but are not identical
    assert d is e      # d and e refer to the same object
    

    There is no equivalent operator to is in JavaScript, and there is no equivalent to JavaScript’s == in Python. Python’s == does type checking for the built-in types.

    The conditional operator (a ? b : c in JavaScript) is written out in Python as:

     b if a else c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.