Skip to content
TeamElGhazi
EN-USChange language
Submit a request
Python: True or False?
Blog: AI, Python, Automation and Web, Answers You Can Verify

Python: z = 1 > 8, then print(z). True or False?

By Abdellah El Ghazi, Python instructor and founder of TeamElGhaziPublished on November 12, 2026

Don't guess. Run the code.

At a glanceWith z = 1 > 8 followed by print(z), Python prints False: 1 is not greater than 8, and that result is stored in z. This article explains what Python does line by line, the six comparison operators, the difference between = and ==, and offers three solved exercises. It is written for middle schoolers, high schoolers, college students and anyone just starting out. All the code was run with Python 3.

Google4,8out of 5 · 11 Google reviews

The article at a glance

Topic
Comparisons and Booleans in Python
Answer
z = 1 > 8 then print(z) prints False
Level
Beginner
Who it's for
Middle schoolers, high schoolers, college students, adults starting out in Python
Code verified with
Python 3 (version 3.12)
Related course
Python Fundamentals, 1.5 months, online and live
The answer in detail

What does Python answer: True or False?

Short answer: False. The comparison 1 > 8 asks a question: "Is 1 greater than 8?" The answer is no. Python stores that no, written False, in the variable z, and then print(z) displays it.

If the exercise is written z = 8 > 1, the answer becomes True. So always check which way the code is written.

z = 1 > 8
print(z)
# Output:
# False

What does Python do, line by line?

The question looks simple. Yet it tests three notions at once: the order in which Python reads a line, the Boolean type, and the difference between storing a value and comparing two values.

  1. Python first evaluates what is on the right of the = sign. The expression 1 > 8 equals False
  2. It then stores that result in the variable z. The = sign is not a math equality. It is an arrow: "put what is on the right into z."
  3. print(z) displays the contents of z, that is, False, with a capital F
  4. z holds a Boolean (type bool): not a number, not a text, only True or False. Every comparison produces one, and type(z) shows it: <class 'bool'>

What are the 6 comparison operators in Python?

Python has six. Each one can only answer True or False.

The most commonly mixed up are >= and <=. 3 >= 3 is true, because "greater than or equal to" accepts equality. 3 > 3 is false.

  • == : equal to. 5 == 5 gives True
  • != : not equal to. 5 != 5 gives False
  • > : strictly greater than. 1 > 8 gives False
  • < : strictly less than. 1 < 8 gives True
  • >= : greater than or equal to. 3 >= 3 gives True
  • <= : less than or equal to. 2 <= 1 gives False

Why can the Arabic-language prompt be misleading?

Many students come across this exercise in a prompt written in Arabic. Arabic is written right to left, code left to right: when a line mixes the two, the screen reorders the display (Unicode's bidirectional rule), and the > sign may be drawn flipped, like a <.

The comparison itself keeps its meaning: the sign flips along with the order of the numbers. The right reflex: Python code is read left to right, with the variable before the = sign. If in doubt, retype the line in an editor and run it.

What is the difference between = and ==?

A single = stores a value in a variable. A double == compares two values and answers True or False. In a condition, you therefore need ==.

Here is Python's actual message when you get it wrong. It even suggests the fix itself. Reading an error message all the way through is a habit to build from the first session.

x = 5
if x = 5:
    print('ok')
# Output:
# SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

How do you chain and combine comparisons?

Once you understand the six operators, you can chain and combine them.

  • Chained comparisons: 10 <= note < 20 reads as in math, "note between 10 inclusive and 20 exclusive."
  • and, or, not combine Booleans. and requires everything to be true, or requires at least one part to be, and not reverses the value
  • The text '10' is not the number 10: the comparison gives False. This is a classic trap with input(), which always returns text
  • True equals 1 and False equals 0 in a calculation. That is why True + True gives 2. Handy for counting correct answers
grade = 14
print(10 <= grade < 20)   # True
print(1 > 8 and 8 > 1)   # False
print(1 > 8 or 8 > 1)    # True
print(not (1 > 8))       # True
print('10' == 10)        # False
print(True + True)       # 2

Three exercises: can you predict the output?

Work out the answer before running the code.

  • Exercise 1: age = 17 then print(age >= 18). Answer: False, because 17 is not greater than or equal to 18
  • Exercise 2: print(3 < 8 < 5). Answer: False. Python reads it as "3 < 8 and 8 < 5," and 8 < 5 is false
  • Exercise 3: print(bool('False')). Answer: True. A non-empty text always equals True, even if it contains the word False

Where can you learn these basics with an instructor?

Operators, conditions and loops open the program of our Python Fundamentals course: one and a half months, online and live, with an automation project at the end. It welcomes all beginners: high schoolers, college students, employees, people changing careers.

Python is also one of the courses we teach at IFIAG, in Casablanca, since October 2026.

Lancé pour de vrai

z = 1 > 8, dans un vrai terminal

Le code de l'exercice, lancé tel quel. La réponse n'est pas une opinion : c'est ce que Python affiche.
comparaison.py
z = 1 > 8print(z)print(type(z))
$ python3 comparaison.py✓ False✓ <class 'bool'>
Ce que demande l'exercice
  • Prévoir ce qu'affiche print(z), avant de lancer le code.
  • Le code se lit de gauche à droite, même dans un énoncé en arabe.
  • 1 n'est pas plus grand que 8 : z reçoit False.
Sortie réelle de Python.
In the field
For
IFIAG, Casablanca
What was done
Artificial intelligence, Python and web development courses taught on site at the institution, with instructor guides, student sheets and mini-quizzes
When
Since October 2026 (2026-2027 school year)

IFIAG

Since October 2026, two tracks, two levels, 40 sessions written in advance.

Format
In class, at the institution
Sector
Private higher education
The case study
Putting it into practice

From == to a project,
Python Fundamentals.

The page where this article turns into a program, a service or a quote.
  • Python Fundamentals

    A program that does a task for you.

    Duration
    1.5 months
    Format
    Online, live with an instructor
    Audience
    Beginners: students, employees, teachers, people changing careers
Frequently asked questions

True, False
and the capital letter.

5 answers

What does print(1 > 8) output in Python?

False. The > operator asks whether 1 is strictly greater than 8. The answer is no, so Python returns the Boolean False. Conversely, print(8 > 1) prints True.

Why are True and False capitalized?

They are the only two values of the bool type, and Python writes them that way. In lowercase, true is not recognized: Python answers NameError: name 'true' is not defined.

Can you compare a text and a number?

With ==, yes, but the answer is False: '10' == 10 gives False. With >, <, >= or <=, Python refuses and answers TypeError. First convert the text to a number with int().

What are comparisons used for in a real program?

To make decisions. An if condition runs a block only if the comparison equals True. A while loop keeps going as long as the comparison equals True.

Which course should you start with to learn these basics?

Start with Python Fundamentals, TeamElGhazi's entry-level course: one and a half months, online and live, no prerequisites. Operators and conditions are in the first module.

Your request

Plan the output,
with a trainer.

in 100 languages
01 · Submit a request
Your request
You
At least one of the two: email or phone.
Sending

Your data is used only to reply to you (Law 09-08, GDPR). Privacy
02 · Meeting30 min

Individuals, institutions, companies: you choose your slot online. A first 30-minute conversation about a project, or your hours of lessons.

Choose a slot
03 · A call, an email06 60 66 59 52

Call us, or write to contact@teamelghazi.com

Service delivered in
  • 100 languages
From Casablanca: on site in Morocco, remotely everywhere.
Submit a requestMeeting