Tin nhắn: 15
Nội dung: Esperanto
Hyperboreus (Xem thông tin cá nhân) 19:20:52 Ngày 23 tháng 4 năm 2012
Lom (Xem thông tin cá nhân) 13:39:02 Ngày 24 tháng 4 năm 2012
Ekzemple: '2 + 2 = ' + str(4)
Mi trovas ĝin pli legebla. Format mi ne multe uzis ĝis nun (fakte mi daŭre lernas pitonon, kaj pro skriptoj en Blender 2.49, daŭre uzas python2.x, sed ja provas pasi al python3.x.), kaj ĝi ŝajnas al mi ĉefe utila por pli bone formatigi nombrojn.
Pri __repr__ mi tute ne sciis. Mi ĉiam uzis __str__. Jen pli da informoj pri tio: http://stackoverflow.com/questions/1436703/differe...(angla).
Jen alia ekzemplo:
#! /usr/bin/env python3Se vi malkomentas la __str__ funkcion, ĝi uzos ĝin anstataŭ __repr__ en "print(spike)".
# -*- coding: utf-8 -*-
# Vidu http://stackoverflow.com/questions/1436703/differe... por la malsameco inter __str__ kaj __repr__
class Hundo:
_def __init__ (self, nomo, agxo):
__self.nomo = nomo
__self.agxo = agxo
_def __repr__ (self):
__return 'repr: Tiu ĉi hundo nomatas "{}" kaj estas {}-aĝa.'.format(self.nomo, self.agxo)
_#def __str__ (self):
__#return 'str: Tiu ĉi hundo nomatas "{}" kaj estas {}-aĝa.'.format(self.nomo, self.agxo)
spike = Hundo ('Spike', 4)
print(spike)
print ('Kun funkcio format: {}'.format (spike) )
print ('Kun operatoro + : ' + str(spike))
P.S.: Mi pli ofte aŭdis "4-jaraĝa" anstataŭ "4-aĝa". Sed mi certas pri la plej korekta versio nun. Mi devus labori anstataŭ ol forumumi. ^^'
Hyperboreus (Xem thông tin cá nhân) 18:06:10 Ngày 24 tháng 4 năm 2012
Lom (Xem thông tin cá nhân) 10:59:11 Ngày 25 tháng 4 năm 2012
![ridulo.gif](/images/smileys/ridulo.gif)
[ Pri Esperanto, mi pensas ke devus esti 'La {} {} saltas super {}.' , ĉu ne? ]
Hyperboreus (Xem thông tin cá nhân) 21:07:35 Ngày 25 tháng 4 năm 2012