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.

Python Python Basics Types and Branching Strings and Operators

Can you explain the why behind variables inside of var?

Can anybody explain why you would create variables inside of other variables, and give some examples? Thanks! Jiles

He is asking about reassigning the variables.Can you please explain on that?

1 Answer

Variables are never created inside variables. variables contain things called objects like strings, integers or floating numbers or any sort of input. For example, Greeting = input("What's up?") here, 'Greeting' is the variable and it contains the string the user responds with to the question "What's up?"

Another example, Greeting = "Welcome to Palm City Beach!" here, 'Greeting' is still the variable but it contains a different value. Instead of an input, it contains a string.

Btw, strings are just alphanumeric characters and r always enclosed in quotation marks.

For example, firstName = input("what is your first name?") print( "Hi my name is", firstName)

in the function print, the string is "Hi my name is" and 'firstName' is the variable.

Steven Parker
Steven Parker
217,532 Points

You might say that object properties are "variables inside of other variables". For example, "name" and "age" are both inside "person":

var name = "Joe";
var age = 22;
var person = { name, age };
console.log("The person's name is " + person.name);
console.log("and they are " + person["age"] + " years old.");

But I'm not sure that was the original question since I don't see how it would relate to this video.