473,505 Members | 13,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Carrying values over in a function

5 New Member
I'm pretty new to python, and I'm currently having problems carrying a value inside a function, to be used again by another function.

I'm not sure if that make sense, and I don't really have a good simple example, sorry.

And since I'm totally new to programming I might just be misunderstanding what a function really does.
Nov 20 '07 #1
3 1586
bartonc
6,596 Recognized Expert Expert
I'm pretty new to python, and I'm currently having problems carrying a value inside a function, to be used again by another function.

I'm not sure if that make sense, and I don't really have a good simple example, sorry.

And since I'm totally new to programming I might just be misunderstanding what a function really does.
I hope this helps with some basic understanding of the way functions work:
Expand|Select|Wrap|Line Numbers
  1. # functions receive values in the parameters given in the fuction call
  2. # and return values that they produce using the return statement
  3.  
  4. def Add(x, y):
  5.     return x + y
  6.  
  7. def Multiply(a, b):
  8.     c = a * b
  9.     return c
  10.  
  11. d = Add(1, 2)
  12. print d
  13.  
  14. e = Multiply(d, 6)
  15. print e
Nov 20 '07 #2
aLiase
5 New Member
I hope this helps with some basic understanding of the way functions work:
Expand|Select|Wrap|Line Numbers
  1. # functions receive values in the parameters given in the fuction call
  2. # and return values that they produce using the return statement
  3.  
  4. def Add(x, y):
  5.     return x + y
  6.  
  7. def Multiply(a, b):
  8.     c = a * b
  9.     return c
  10.  
  11. d = Add(1, 2)
  12. print d
  13.  
  14. e = Multiply(d, 6)
  15. print e
Yes, that really helped thanks, program works fine now : D.

I didn't actually know you could assign a variable to a function.
Nov 20 '07 #3
bartonc
6,596 Recognized Expert Expert
Yes, that really helped thanks, program works fine now : D.

I didn't actually know you could assign a variable to a function.
I remember programming in Pascal. Back then we were force to make a distinction between functions and procedures. For Python this is not so. But there some little pieces of trivia that is good to know...
  1. When a function (or method of an object) does not explicitly return a value, Python automatically returns None.
  2. Even if a function returns a value you are not require to assign it to a variable.
Nov 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6258
by: Ralph Freshour | last post by:
I was reading about PHP variable scoping - it doesn't seem to support carrying any variables from one web page to another - how is this usually done? I have a lot of php variables created on my...
13
1724
by: G | last post by:
Hello, Is it possible to send form values from PAGE1 to PAGE2, and then retain the form info for PAGE3 without using cookies, sessions or DB storage? Also, I dont want to repost page2 to page3...
36
10009
by: Richard | last post by:
My employer currently pays me $1/hour when I carry a pager. I have to carry the pager every fourth week. The problem is that my employer insists that I be available when I'm carrying the pager. ...
4
3769
by: Ivan Shevanski | last post by:
Alright heres my problem. . .Say I want to carry over a variable from one function to another or even another run of the same function. Is that possible? Heres a quick example of what I'm talking...
1
2062
by: Ani | last post by:
Hi, I need to carry the user input across pages and then at the end insert all the values into the DB. How do I best accomplish this task in ASP.Net. I am a novice , please give me some simple...
4
2135
by: Matt | last post by:
I have the following in a page and I am trying to update a record on the next page but for some reason the form data is not carrying over. Any ideas why? <form name=nxtlupdate method=post...
1
5052
devonknows
by: devonknows | last post by:
Hi, im having trouble carrying variables across a form, ive looked on here and other sites but cant find anything that helps me, or i might not be searching for the right terms, so i though i would...
4
14090
by: Kurrent | last post by:
I have some data from text fields that are being passed over through a form that I am displaying with the $_POST superglobal. Once i have echo'd out this data onto the next page, i'd like to...
4
1782
by: Jeff | last post by:
I've been struggling with this for a while. Here's what I'm trying to do: private function makeMiniTemplate($ARRAY){ /* $ARRAY looks like this: $ARRAY='Some Value';
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.