Guest User

Untitled

a guest
Oct 12th, 2021
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Consider:
  2.  
  3. course_db = Course(title='Databases')
  4. course_db.save()
  5.  
  6. Coming from a C++ background, I would expect `(course_db = Course(title='Databases'))` to behave like it would in C++, that is assign `Course(title='Databases')` to `course_db` *and return the assigned object so that I can use it as part of a larger expression*. For example, I would expect this code to do the same thing as the code above:
  7.  
  8. (course_db = Course(title='Databases')).save()
  9.  
  10. But when I tried this, I got a syntax error.
  11.  
  12. Why can't I do this in Python, and what can I do instead?
RAW Paste Data