fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
      • 7
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
      • 16
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19

  • Boolean variables

    So far we have seen textual variables as well as numeric integer variables. We will cover boolean variables and their use cases in the coming few exercises.
    Boolean variables can only take two values True and False. They can represent if some statement holds a true condition or is a false statement.
    is_better = True
    sometimes = False
    playing_football = True
    hello = False
    print(sometimes, playing_football)
    This program would print False True as the value of sometimes is set to be False and the value of playing_football is set to be True.
    To get types of variables we can use the type function.
    a = True
    b = 123
    c = 'hello'
    print(type(a), type(b), type(c), type(1234))
    This program would print <class 'bool'> <class 'int'> <class 'str'> <class 'int'>. Meaning that:
    • a is of type bool (a boolean variable which can be either True or False)
    • b is of type int (a numeric integer variable)
    • c of type str (a textual/string variable)
    • 1234 is of type int (a numeric value)


    Create a numeric variable favorite and assign your favorite number to it. Create a variable best and assign True to it.
    Your program should print the types of variables favorite and best in the output as well as the types of True, False, and 'long long text'.
    To check your solution you need to sign in
    Sign in to continue