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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:13:31+00:00 2026-06-16T00:13:31+00:00

In C++ you can do the following: int x = 10; int &y =

  • 0

In C++ you can do the following:

int x = 10;
int &y = x;
y = 11;
cout << x << endl; // will print 11

How can I do something similar in python? Trying to make self.session a reference to self.request.session:

self.session = self.request.session
  • 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-16T00:13:32+00:00Added an answer on June 16, 2026 at 12:13 am

    The following will make both self.session and self.request.session refer to the same object:

    self.session = self.request.session
    

    If you make a change to session via either of the two references, you’ll be able to observe the change through both:

     self.session.set_foo(42)
     self.request.session.get_foo() # returns 42
    

    If you, on the other hand, rebind either reference by making it point someplace else, that’ll break the link:

     self.session = another_session
    

    Finally, it is important to note that certain Python types are immutable. This includes integers, strings and tuples. While you can have multiple references to an immutable object, the immutability prevents you from making any changes to that object.

    This is relevant in light of your C++ example. If you wanted to have a shared reference to an int, and be able to modify that int, you’d have to wrap the int inside a mutable object, and share references to that mutable object instead.

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

Sidebar

Related Questions

I'm trying to print the value returned by the following code: Agent** Grid::GetAgent(int x,
How can the following simple implementation of sum be faster? private long sum( int
With a vector, I can do the following: vector<int> myvec (4,100); int first =
How can I rewrite he following code using C#3.0 automatic properties? private int _myValue;
can we declare a function in a header file in following way? extern int
The following code prints '2' four times. Why does it never print '1'? Can
The following code will wait for a child process to finish and then print
I wrote the following function and works fine: int NetworkSocket::readDatagrams(unsigned char *buffer, string &srcAddress,
I have following code class Test { public: int &ref; int a; Test(int &x)
I can't figure out why the following code compiles fine: #include <iostream> void bar(int

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.