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 2.0 Basics An Introduction to Swift Programming Working With Variables

I'm having difficulty understanding variable and constants

the video is too fasts

variables.swift
// Enter your code below

1 Answer

Hi Bright!

A variable is a label that can contain a value that you want to use again and again in your programs.

For example, instead of doing the following:

print("Hi, my name is Luke")
print ("I am called Luke")

You can do this:

var name = Luke
print ("Hi, my name is \(name)")
print("I am called \(name)")

This way, you only have to change the value that is assigned to 'name' rather than changing the print statements output more than once.

The difference between variables and constants is pretty simple. One can be changed as it's a 'variable' value and the other is a 'constant' value so it cannot change and always remains the same.

I hope that this helped you out! If you need any more help then don't hesitate to ask.

-Luke

thank you Luke!

No problem, glad I could help you out! Don't forget to mark a 'Best Answer' so other members of the Treehouse community know that your problem has been solved.