PieceOfAPie
PieceOfAPie
  • Home
  • Tutorials
  • More
    • Home
    • Tutorials
  • Home
  • Tutorials

Operators

Previous Lesson


In Python, we can use operators like addition and subtraction. You can use operators on integers. Here are some examples:

  • Addition: + adds two integers or strings
  • Subtraction: - subtracts two integers
  • Multiplication: * multiplies two integers
  • Division: / divides two integers
  • Modulus: % returns the remainder of the quotient of two integers
  • Exponentiation: ** exponents
  • Floor Division: // divides two integers ignoring the remainder

Here are some examples with variables:

Examples

Boolean Expressions

In Python, we can use boolean expressions to compare data types. Here are some examples:

  • ==: Compares if one value is equal to another
  • >: Compares if one value is greater than the other
  • <: Compares if one value is less than the other
  • >=: Compares if one value is greater than or equal to the other
  • <=: Compares if one value is less than or equal to the other
  • !=: Compares if one value is not equal to the other
  • and: conjunction  (We use this in Python. In other languages it might be &&)
  • not: conjunction (We use this in Python. In other languages it might be ||)
  • or: conjunction (We use this in Python. In other languages it might be !)

Here are some examples with variables:

Examples

Operators and Boolean Expressions Exercise

Determine if each condition is true or false.

  • x = 5
  • y = 9
  • y % x == 1


  • string = "Hello"
  • stringTwo = "Hi"
  • string + stringTwo == "Hello Hi"


  • 11 // 4 >= 3


  • 2 ** 3 <= 8


  • 9 * 8 != 74

Next Lesson

Prints, Inputs, and Concatenation

Copyright © 2024 PieceOfAPie - All Rights Reserved.

Powered by GoDaddy

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

Accept