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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:58:31+00:00 2026-06-07T10:58:31+00:00

>>> def nil(): … ss=’nil’ … print ss … >>> nil() nil >>> nil.ss=’kk’

  • 0
>>> def nil():
...     ss='nil'
...     print ss
... 
>>> nil()
nil
>>> nil.ss='kk'
>>> nil()
nil
>>> print nil.ss
kk

I know everything is an object in python, so function is also an object, now I wanna change the value of ‘ss’ variable, which is stored in function , now I tried to change its value by using nil.ss but it didn;t change..What is the diff between both ‘ss’?

  • 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-07T10:58:33+00:00Added an answer on June 7, 2026 at 10:58 am

    The first ss is an inner variable of the function; the second one is an attribute of the function. They don’t reference the same object.

    Here’s a way to do it, though:

    >>> def apple():
        if not hasattr(apple, 'ss'):  # This way it'll only be set inside the function once
            apple.ss = 'nil'
        return apple.ss
    
    >>> apple()
    'nil'
    >>> apple.ss
    'nil'
    >>> apple.ss = 'kk'
    >>> apple.ss
    'kk'
    >>> apple()
    'kk'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def divideset(rows, column, value) split_function = nil if value.is_a?(Fixnum) || value.is_a?(Float) split_function = lambda{|row|
@@timestamp = nil def generate_oauth_url @@timestamp = timestamp url = CONNECT_URL + REQUEST_TOKEN_PATH +
Error: undefined method `author' for nil:NilClass In my helper: def last_updated(group) g = group.last_updated_version
My Controller (User Controller) def reset_password @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil? if request.post? if
My Controller (User Controller) def reset_password @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil? if request.post? if
I have this simple helper: def printe_result(data) a_var = ('<a href=http://'+data.a_value+'>A</a>' unless (data.a_value.nil? ||
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def myFunc( a, b ): def innerFunc( c ): print c innerFunc( 2 )
Class TShirt def size(suggested_size) if suggested_size == nil size = please choose a size
I'm attempting to change the nil possibility of a boolean attribute on the existing

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.