Changing Variables, I'm really basic

This is the place for queries that don't fit in any of the other categories.

Changing Variables, I'm really basic

Postby Stalagmight » Thu Jul 11, 2013 5:04 pm

Hi!
I am really basic at Python, but am keen to get more as I am beginning a Computer Science course next year.

If I had a variable, e.g 'X' with a value of 10
How do I change the variable to 20, but via adding 10 so that it would work again.

Thank you very much
Stalagmight
 
Posts: 1
Joined: Thu Jul 11, 2013 4:57 pm

Re: Changing Variables, I'm really basic

Postby Marbelous » Thu Jul 11, 2013 5:31 pm

Not sure exactly what you're asking but...

Code: Select all
x = 10
x = x + 10
print x
20


Are you talking about something as simple as that?
Marbelous
 
Posts: 63
Joined: Fri May 31, 2013 8:12 pm

Re: Changing Variables, I'm really basic

Postby stranac » Thu Jul 11, 2013 5:31 pm

Either of these would work:
Code: Select all
x += 10
# or
x = x + 10

Reading a beginner book or tutorial would probably be a good idea.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 896
Joined: Thu Feb 07, 2013 3:42 pm

Re: Changing Variables, I'm really basic

Postby micseydel » Thu Jul 11, 2013 11:38 pm

Do note that in the context of functions, things change. Also, read this.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 929
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron