0
0
Pythonprogramming~15 mins

Self reference in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Self Reference in Python
📖 Scenario: Imagine you are creating a simple program to represent a person who can introduce themselves by name.
🎯 Goal: You will build a small program where a variable refers to itself to print a self-introduction message.
📋 What You'll Learn
Create a variable with a person's name
Create a variable that holds a message referencing the name variable
Use self reference to build the message
Print the final self-introduction message
💡 Why This Matters
🌍 Real World
Self reference is useful when you want to build messages or data that depend on existing variables, like user profiles or personalized greetings.
💼 Career
Understanding how variables can refer to themselves or be used inside functions is a basic skill for programming jobs involving data handling and user interaction.
Progress0 / 4 steps
1
Create a variable with the name
Create a variable called name and set it to the string "Alice".
Python
Need a hint?

Use the equals sign = to assign the string "Alice" to the variable name.

2
Create a self-reference message
Create a variable called message that uses the variable name to build the string "Hello, my name is Alice." using an f-string.
Python
Need a hint?

Use an f-string like f"Hello, my name is {name}." to include the variable name inside the string.

3
Use self reference in a function
Define a function called introduce that takes no parameters and returns the message variable. Use the message variable inside the function to refer to the self-introduction message.
Python
Need a hint?

Define the function with def introduce(): and return the variable message inside it.

4
Print the self-introduction message
Call the function introduce() and print its return value.
Python
Need a hint?

Use print(introduce()) to show the message on the screen.