| | |
"object , object" concatination?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2006
Posts: 5
Reputation:
Solved Threads: 0
hey yo's,
i pretty much understand this function, except for the return value. i know that string , string concats the strings. but what does the comma in the middle do when you have 2 different objects on either side as in the return value below?
i pretty much understand this function, except for the return value. i know that string , string concats the strings. but what does the comma in the middle do when you have 2 different objects on either side as in the return value below?
Python Syntax (Toggle Plain Text)
def load_image(name, colorkey=None): fullname = os.path.join('data', name) try: image = pygame.image.load(fullname) except pygame.error, message: print Cannot load image:, name raise SystemExit, message image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0,0)) image.set_colorkey(colorkey, RLEACCEL) return image, image.get_rect()
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Hi!
Huh? Can you give an example?
It just separates them
So you can return more than one value. Have a look:
Regards, mawe
•
•
•
•
Originally Posted by senateboy
i know that string , string concats the strings
•
•
•
•
Originally Posted by senateboy
what does the comma in the middle do when you have 2 different objects on either side as in the return value below?
So you can return more than one value. Have a look: Python Syntax (Toggle Plain Text)
def lala(a,b): a += 2 b += 2 # return both, the new a and the new b return a, b x, y = lala(1,2) print x, y
Regards, mawe
•
•
Join Date: Jan 2006
Posts: 5
Reputation:
Solved Threads: 0
commas act as concatination in this example:
this produces the string "i love cities like San Francisco"
ok so i understand now that a function can return 2 objects. so what is the function techincaly returning? a list? list of objects. once more? how does the "," comma act in your example:
i just dont see how it werks. i can memorize it but id rather understand it under the hood.
Python Syntax (Toggle Plain Text)
#string concatination with a comma "i love cities" , "like San Francisco"
ok so i understand now that a function can return 2 objects. so what is the function techincaly returning? a list? list of objects. once more? how does the "," comma act in your example:
Python Syntax (Toggle Plain Text)
x, y = lala(1,2)
i just dont see how it werks. i can memorize it but id rather understand it under the hood.
Maybe this example from the "Starting Python" sticky will help ...
[php]
# use a tuple to return multiple items from a function
# a tuple is a set of values separated by commas
def multiReturn():
return 3.14, "frivolous lawsuits", "Good 'N' Plenty"
# show the returned tuple
# notice that it is enclosed in ()
print multiReturn()
# load to a tuple of variables
num, str1, str2 = multiReturn()
print num
print str1
print str2
# or pick just the element at index 1, should be same as str1
# tuples start at index zero just like lists etc.
print multiReturn()[1]
[/php]
[php]
# use a tuple to return multiple items from a function
# a tuple is a set of values separated by commas
def multiReturn():
return 3.14, "frivolous lawsuits", "Good 'N' Plenty"
# show the returned tuple
# notice that it is enclosed in ()
print multiReturn()
# load to a tuple of variables
num, str1, str2 = multiReturn()
print num
print str1
print str2
# or pick just the element at index 1, should be same as str1
# tuples start at index zero just like lists etc.
print multiReturn()[1]
[/php]
May 'the Google' be with you!
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
•
•
•
•
Originally Posted by senateboy
commas act as concatination in this example:

Python Syntax (Toggle Plain Text)
x = "a", "b" print x # -> ('a', 'b')
I think the following confuses our friend senateboy
Python Syntax (Toggle Plain Text)
print "hot", "dog" # -> hot dog str1 = "hot", "dog" print str1 # -> ('hot', 'dog')
May 'the Google' be with you!
![]() |
Similar Threads
- VB.NET Web service using COM component - "Object variable or With block variable ..." (VB.NET)
- RUNDLL error "Bridge.dll" (Viruses, Spyware and other Nasties)
- error loading "Bridge.dll" (Windows 95 / 98 / Me)
- Hotmail "error on page" problem (Web Browsers)
Other Threads in the Python Forum
- Previous Thread: Best way to convert C++ coding to Python
- Next Thread: python IDE
Views: 5228 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Python
approximation array beginner book builtin change cipher clear client code color converter countpasswordentry cturtle curved def dictionary drive dynamic examples excel file float format ftp function gui homework import inches input java library line lines linux list lists loop microcontroller mouse mysqldb mysqlquery newb number numbers output parsing path plugin port prime program programming projects py2exe pygame pymailer pyqt python random recursion recursive redirect remote script scrolledtext search singleton socket sqlite ssh string strings strip subprocess sum syntax table terminal text textarea thread threading time tkinter tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable vigenere wikipedia windows wxpython xlwt






