Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.