Python Program to Display a Welcome Message
Beginner · Basics · CBSE class 11 practical list
This is usually the first program in a Python practical file. It stores a welcome message in a variable and displays it on the screen. It shows two things almost every program does: keep a value and print output.
Program
welcome_message.py
message = "Welcome to Python programming!" # or: message = input("Enter a welcome message: ")
print("Your welcome message is:")
print(message)
print("It has", len(message), "characters.")
Output
Your welcome message is: Welcome to Python programming! It has 30 characters.
How it works
- The text is stored in a variable called
message, and the comment shows theinput()version that lets the user type it. - Text inside quotes is a string, so Python prints it exactly as written.
print()displays whatever you pass it, and each call starts on a new line.- When
print()gets several values separated by commas, it puts a space between them, which is how the last line mixes text withlen(message).
Another way to write it
Welcome a user by name
Welcome a user by name
name = "Riya" # or: name = input("Enter your name: ")
message = "Welcome, " + name + "!"
border = "*" * (len(message) + 4)
print(border)
print("*", message, "*")
print(border)
Output
****************** * Welcome, Riya! * ******************
Joining strings with + builds the message, and "*" * n repeats a star n times to draw a border that fits it.
Try it yourself
Put your own name in message and add a line that prints the name of your school.
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises