Do you know what is CONCATENATION?
To remember the word, here is a trick!
I call it CON – CAT – TEN – NATION. Smart right?
You know why it’s called concatenation? Because it is called conning the cat in ten nations.
Jokes aside, here is what “concatenation” really means.
Concatenation is something like putting two words together using “+” is Python. Like when you want to connect “He’s” with “smelly” together we use Concatenation!
When we connect those two words in one sentence and print it out later, it would show “He’ssmelly”. If we put a space behind the first word, or put a space in front of the second word, it would show “He’s smelly”. It is nicer.
here is an example of Concatenation:
user_first_name = input("What is your first name?")
user_surname = input("What is your surname?")
user_year = int(input("What is your year of birth?"))
user_age = 2023 - user_year
full_info = "Hello, " + user_first_name + " " + user_surname + "." + " You are " + str(user_age) + " years old."
print(full_info)
In this example, Concatenation happens on line 6.
In the first three lines, we ask the user for three things–
- First name
- Surname
- Year of birth
( They are just examples, you can also choose age, birthday date, hobbies etc.)
This is the part where we just stick them altogether!
user_info = "Your name is " + user_first_name + " " + user_surname + ", and you are " + user_age + " years old."
(Pretend) Your name is Maria and your surname is Chan. You were born in 2009.
What it will show: Your name is Maria Chan, and you are 14 years old.
This is how concatenation works. Do you understand?
Well, i’m sure you do! stay tuned for more lessons, or you can check out my drawings or my blog.
Goodbye, see you at the next lesson!