Why not just put my name in the string?

Couldn’t we just put our name within the print program as opposed to a different line?

21 Likes

Well, that would not be following the instructions to the letter, which you might find around here goes a long way to a good learning experience.

The lesson shows us how a variable can be assigned with a value, then interpolated into a string and outputed to the console.

There are a number of concepts demonstrated…

  1. strings
  2. variables
  3. assignment
  4. concatenation
  5. printing
100 Likes

Thanks Roy! I’m a beginner and just wanted to be the guy to ask questions about everything for better understanding. Kind of self-teaching/ learning this stuff, not the easiest task.

76 Likes

With more experience the usefulness of this will become understood. It’s a small part of a bigger picture.

16 Likes

Is it necessary to write a variable as my_name, can’t we write like my name?

3 Likes

@giga0346789029, variable names, among other constraints, must include no spaces.

11 Likes

Thanks for help, it means a lot.

Good question for a newbie programmer, the answer would be… best to use variables sometimes for programs. imagine the script is much longer and your name appears at other areas. instead of updating all those lines of code you just update the variable at the top. It would save time and cascade to the rest of the code.

120 Likes

Thanks, this answer is much more make sense for a newbie.

4 Likes

Yes, but the point of the lesson was to show the usefulness of a computer program. When variables are used, the user can just input a name into the variable and then the program will print a message containing the name. If a different name is entered, a different message will be printed back. A computer program is only useful if it responds to user requests.

If you want to have all the code on one line, you can use a semicolon to divide the two code pieces like this: But it is not recommended as it makes the code harder to read.

my_name = "Codecademy"; print("Hello and welcome " + my_name + "!")

12 Likes

He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever.

-Chinese Proverb

54 Likes

Malcom Mcginty i need help

If you’re looking for help from the community I encourage you to view the following FAQ which details how and where to ask your question in order to get the best chance at a response-

Since this a rather dated thread it may be worthwhile adding a new query unless it directly relates to the posts above.

I love this python learning, but learning by self is the greatest task since some of us come from poor families that can’t afford paying for university

7 Likes

trust me, ive payed thousands to learn something I could do myself
you are doing yourself a favor by learning it on your own

5 Likes

Your name here is a variable and should be defined before using it. Here, we’re printing, but in the future, we’ll be manipulating variables in other ways. Using this method, we can easily import a long list of variables for various functions.

1 Like

I guess you can also use MyName?

1 Like

Merci beaucoup pour tout

I am new into the world of coding and programming. Having said that I think I have just passed the phase to understand why variables are used and their importance. From my personal experience, I don’t think a small program like this, allows us to understand the importance of a variable or what is the practical use of a variable. I have always wondered, what’s the need of variable when I can type in manually (infact I have to do it in this program). Only after studing and observing referrences, I truly realized the practical importance of a variable.

2 Likes

Would somebody clarify how some text has different colours than others?

1 Like