[Tutor] Getting error on my code
Dappy Jr
oladaposegun62 at gmail.com
Fri Jan 31 13:36:06 EST 2025
Thanks y'all for the directions and inputs, it really helped..
On Fri, Jan 31, 2025 at 4:43 PM ThreeBlindQuarks via Tutor <tutor at python.org>
wrote:
> Sometimes a + is not a plus.
>
>
> Sent with Proton Mail secure email.
>
> On Friday, January 31st, 2025 at 8:10 AM, Alan Gauld via Tutor <
> tutor at python.org> wrote:
>
> > On 31/01/2025 12:36, Leam Hall via Tutor wrote:
> >
> > > On 1/31/25 06:10, Alan Gauld via Tutor wrote:
> > >
> > > > On 31/01/2025 10:46, Leam Hall via Tutor wrote:
> > > >
> > > > > > def_init_(self , name , age):
> > > > > > self.name = name
> > > > > > self.age = age
> > > > > > print(self.name.title() + self.age)
> > > >
> > > > > 2. Made the age a string in the init print method.
> > > >
> > > > As a matter of interest, why?
> > > > print() converts its arguments to strings internally
> > > > so why the explicit conversion?
> > >
> > > Sorry, coffee still kicking in. If we redo the print statement without
> the concat, it does the conversion:
> > >
> > > print(self.name.title(), self.age)
> >
> >
> > Yes, the plus made print() treat the whole as a single string
> > so it would need the str() call.
> >
> > I should have spotted that too! :-)
> >
> > --
> > Alan G
> > Author of the Learn to Program web site
> > http://www.alan-g.me.uk/
> > http://www.amazon.com/author/alan_gauld
> > Follow my photo-blog on Flickr at:
> > http://www.flickr.com/photos/alangauldphotos
> >
> >
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list