Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics (retired) Collections What is a Dictionary?

what is difference between constant and variable

what is difference between constant and variable

1 Answer

Jari Koopman
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jari Koopman
Python Web Development Techdegree Graduate 29,349 Points

Hi Matan,

There is only one very simple difference between a variable and a constant, and the name already says it. A variable is variable, what means that you can change it's content later in you code, with a constant you cant. For example if you set a var named var1 with the string: "i am a var" and later on you set var1 = "i still am a var" and than print var1 you will get "i still am a var". With a constant (let) when you try to change it's content Xcode will start complaining because something that's constant can't change. I hope that it's clear now.