Python Concepts/Quizzes/Introduction

Python quiz &mdash; Introduction: It is sometimes said that Python is a very readable language. So if you have some previous experience with a programming language you might be able to guess and answer the following questions even though you haven't learnt Python. The Python prompt with the command from an interactive Python session is indicated with ">>>".

{The following Python code results in + 12 - An error: You need to make an assignment to a variable - Another result
 * type=""}
 * Assignments are not necessary

{The following Python code results in - 4 + 4.0 - An error: You need to make a conversion between a float and an integer - Another result
 * type=""}
 * There is a difference between integers and floats in Python

{The following Python code results in - 4.5 - 4 + 1 - Another result
 * type=""}
 * Use '/' for division
 * Use '/' for division. Use '//' for integer division.
 * This is the modulus for the remainder (not that obvious)

{The following Python code results in + a is the boolean False - a is the boolean True - a is the string 'hello there' - b is the boolean False - b is the boolean True + b is the string 'hello there'
 * type="[]"}
 * But used in a control structure 'b' is True

{The following control structure results in - n is assigned to 2 - The string "Hello" is printed to the standard out + The string "World" is printed to the standard out - The string "Nothing" is printed to the standard out
 * type=""}
 * This is a standard "if" sentence. Note the "elif" rather than "else if" or "elseif".

{The following control structures results in 'n' being assigned - 3 - 7 - 8 + 10 - 12 - Another integer - An error since the first 'if' sentence is not completed.
 * type=""}
 * The lack of indentation completes the 'if' sentence

{ results in + A function "f" is defined - A integer "f" is defined + A variable 'a' is assigned the value of 4
 * type="[]"}
 * Note that most thing in Python are actually objects.

{ results 'a' being - [1, 2, 3] - [6, 8, 12] - [6, 8, 12, 17] - [6, 8, 12, 18] - [1, 2, 3, 6, 8, 12] + [1, 2, 3, 6, 8, 12, 17] - [1, 2, 3, 6, 8, 12, 18] - [1, 2, 3, 6, 8, 12, 17, 18] - An error - Other result
 * type=""}

{ -+ 'Rational' is a function +- 'Rational' is a class +- '__init__' is a constructor -+ '__init__' is a destructor +- 'reduce' is a method -+ 'print(r)' will print '3' +- 'r.reduce(3); print(r)' will print '1/3'
 * type=""}
 * True | False

{The following code defines 3 variables It results in: + seq is list: [ ] + 'oeis' is a data structure that can be indexed by a string. + oeis['A000079'] is a function + 'b' is True
 * type="[]"}
 * It is constructed by a "list comprehension". Some of the perhaps less readable part of Python
 * The 'lambda' keyword indicates an anonymous function