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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:33:43+00:00 2026-06-15T17:33:43+00:00

So I wrote this function from a book I am reading, and this is

  • 0

So I wrote this function from a book I am reading, and this is how it starts:

def cheese_and_crackers(cheese_count, boxes_of_crackers):
    print "You have %d cheeses!" % cheese_count
    print "You have %d boxes of crackers!" % boxes_of_crackers
    print "Man that's enough for a party!"
    print "Get a blanket.\n"

ok, makes sense. and then, this is when this function is run where I got a little confused and wanted to confirm something:

print "OR, we can use variables from our script:"
amount_of_cheese = 10
amount_of_crackers = 50  

cheese_and_crackers(amount_of_cheese, amount_of_crackers)

the thing that confused me here is that the amount_of_cheese and amount_of_crackers is changing the variables (verbage? not sure if i am saying the right lingo) from cheese_count and boxes_of_crackers repectively from the first inital variable labels in the function.

so my question is, when you are using a different variable from the one that is used in the initial function you wrote, why would you change the name of the AFTER you wrote out the new variable names? how would the program know what the new variables are if it is shown after it?

i thought python reads programs top to bottom, or does it do it bottom to top?

does that make sense? i’m not sure how to explain it. thank you for any help. 🙂
(python 2.7)

  • 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-15T17:33:43+00:00Added an answer on June 15, 2026 at 5:33 pm

    I think you are just a bit confused on the naming rules for parameter passing.

    Consider:

    def foo(a, b):
        print a
        print b
    

    and you can call foo as follows:

    x = 1
    y = 2
    foo(x, y)
    

    and you’ll see:

    1
    2
    

    The variable names of the arguments (a, b) in the function signature (1st line of function definition) do not have to agree with the actual variable names used when you invoke the function.

    Think of it as this, when you call:

    foo(x, y)
    

    It’s saying: “invoke the function foo; pass x in as a, pass y in as b“. Furthermore, the arguments here are passed in as copies, so if you were to modify them inside the function, it won’t change the values outside of the function, from where it was invoked. Consider the following:

    def bar(a, b):
        a = a + 1
        b = b + 2
        print a
    
    x = 0
    y = 0
    bar(x, y)
    print x
    print y
    

    and you’ll see:

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

Sidebar

Related Questions

I wrote this little function to fill a drop down list with data from
I wrote a Delphi function retrieving a web page from another application. This works
Hi I have been learning php from this book PHP Solutions Dynamic Web Design
I wrote this function to get minutes from a date, but I cannot get
I have sort of a beginning of a solution. I wrote this function (Sorry
I wrote this function to make columns sortable. I want to rearrange divs based
I wrote this function for filling closed loop, pixvali is declared globally to store
I wrote this function to get the unread count of google reader items. function
I wrote this function to get a pseudo random float between 0 .. 1
I wrote this function to communicate with an external program. Such program takes input

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.