How to write "I love you" in Python
The short answer is one line: print("I love you"). Below are eight more ways to say it with code, from printing it 100 times to hiding it in binary. Press Run on any example to try it, and change the words to make it your own.
On this page
The one-line answer
In Python, print() shows whatever you put inside its brackets. Text goes inside quote marks, so this is all you need:
I love you
The quote marks tell Python that I love you is text, not a command. Leave them out and Python tries to understand each word as code, and stops with a SyntaxError.
Say it to someone by name
Keep the name in a variable, then use an f-string to slot it into the message. The f before the quotes lets you put a variable inside curly brackets.
I love you, Sam!
To let the person type their own name, use input(). Press Run, type a name in the output box and press Enter.
Who is this message for? Sam I love you, Sam!
Shown with the answers 'Sam'. Press Run to type your own.
Print "I love you" 100 times
A for loop repeats the lines indented under it. range(1, 101) counts from 1 up to 100 (the stop number is never included), so the message prints 100 times, numbered:
1 I love you 2 I love you 3 I love you 4 I love you 5 I love you 6 I love you 7 I love you 8 I love you 9 I love you 10 I love you 11 I love you 12 I love you 13 I love you 14 I love you 15 I love you 16 I love you 17 I love you 18 I love you 19 I love you 20 I love you 21 I love you 22 I love you 23 I love you 24 I love you 25 I love you 26 I love you 27 I love you 28 I love you 29 I love you 30 I love you 31 I love you 32 I love you 33 I love you 34 I love you 35 I love you 36 I love you 37 I love you 38 I love you 39 I love you 40 I love you 41 I love you 42 I love you 43 I love you 44 I love you 45 I love you 46 I love you 47 I love you 48 I love you 49 I love you 50 I love you 51 I love you 52 I love you 53 I love you 54 I love you 55 I love you 56 I love you 57 I love you 58 I love you 59 I love you 60 I love you 61 I love you 62 I love you 63 I love you 64 I love you 65 I love you 66 I love you 67 I love you 68 I love you 69 I love you 70 I love you 71 I love you 72 I love you 73 I love you 74 I love you 75 I love you 76 I love you 77 I love you 78 I love you 79 I love you 80 I love you 81 I love you 82 I love you 83 I love you 84 I love you 85 I love you 86 I love you 87 I love you 88 I love you 89 I love you 90 I love you 91 I love you 92 I love you 93 I love you 94 I love you 95 I love you 96 I love you 97 I love you 98 I love you 99 I love you 100 I love you
If you just want the words repeated on one line, multiply the text. In Python, text times a number repeats it:
I love you! I love you! I love you!
I love you in number code: 143
143 is a well-known number code for "I love you", popular back when people sent messages to pagers: 1 letter in I, 4 in love and 3 in you. Python can work it out for any message by counting the letters in each word:
143
split() breaks the text into a list of words, len() counts the letters, and str() turns each count into text so it can be joined on. Try changing the message to I miss you.
Another one you may see is 831: 8 letters, 3 words, 1 meaning.
8 3 1
I love you in binary
Computers store every letter as a number, and every number as ones and zeros. ord() gives a letter's number, and format(..., "08b") writes it as 8 binary digits:
01001001 00100000 01101100 01101111 01110110 01100101 00100000 01111001 01101111 01110101
To read a binary message back, turn each group into a number with int(code, 2), then into a letter with chr():
I love you
I love you in Morse code
A dictionary is perfect for codes: each letter is a key, and its Morse code is the value. This prints the message with a slash between words:
.. / .-.. --- ...- . / -.-- --- ..-
Backwards, in capitals, or in a frame
Text has lots of handy tools. [::-1] reads it backwards, upper() makes capitals, and center() pads it on both sides with any character:
uoy evol I I LOVE YOU ♥♥♥♥♥♥♥I love you♥♥♥♥♥♥♥
A love letter generator
Put it all together: ask three questions, then print a letter built from the answers. int() turns the typed number into a real number, so Python could do maths with it.
Who is the letter for? Mum What do you love most about them? your laugh How many years have you known them? 12 Dear Mum, I love you, and I love your laugh. That's 12 years of being happy you're here. Love, Me
Shown with the answers 'Mum', 'your laugh', '12'. Press Run to type your own.
Want it as a picture instead? The Python heart code page draws a red heart with your words inside it.
Running it on your own computer
Everything here runs in your browser, but it works the same in any Python. Save the code in a file such as love.py and run python love.py, or paste it into IDLE, which comes with Python.
Play the game version
Each of these games teaches one idea from this page, with a short narrated video and six levels to clear.
Questions people ask
How do you write I love you in Python?
Type print("I love you") and run it. print() shows whatever is inside its brackets, and the quote marks tell Python the words are text.
What does 143 mean in code?
143 means "I love you": the words have 1, 4 and 3 letters. It was a popular pager code. In Python you can work it out by joining len() of each word.
How do I print I love you 100 times in Python?
Use a loop: for number in range(100): print("I love you"). range(100) runs the loop 100 times. Or print("I love you\n" * 100) repeats the text with a new line each time.
How do you say I love you in binary?
I love you in 8-bit binary is 01001001 00100000 01101100 01101111 01110110 01100101 00100000 01111001 01101111 01110101. Python makes it with format(ord(letter), "08b") for each letter.
What does 831 mean?
831 is another way to say "I love you": 8 letters, 3 words, 1 meaning.
Learn Python with games
Every idea on this page has its own game in the course, with a short video and six levels. The three games in Module 1 are free: no account, nothing to install.
Every idea on this page has its own game in the course. Pick up where you left off.
Play the first game freeContinue the courseMore fun python code
Python heart code: draw a heart with turtle or text
Copy-and-run Python heart code: a heart made of stars, a heart filled with LOVE, and red turtle hearts. Change the colours and add a name.
Happy birthday code in Python
Happy birthday in Python: a text cake, the song with a loop, a typing effect, candles for any age, and a countdown to your birthday.
More free ways to learn
Practice
Free Python practice online: exercises with answers you check in your browser, plus 79 coding games, one for every beginner topic.
Teach
Free resources for teaching Python to kids and beginners: a Scratch to Python guide, printable worksheets with answers, and a game-based course.
Guides
Short guides on learning Python with games, how long it takes, and where to start.