Learning Journal
Learning Journal
If you are trying to print a string, what happens if you leave out one of the quotation marks
or both and why?
That’s because it is not possible to determine the beginning or end of the string to be displayed
without both of the quatation marks (Downey, A., 2015).
Printing without both quotation marks will encounter a syntax error as well because the interpreter
can't parse the code, for example :
However omitting both of the quotation marks when printing numeric values, makes the output
comes out correct ; which is the same numeric value written in the statement, for example :
>>> print (2021)
2021
You can use a minus sign to make a negative number like -2. What happens for each of the
following and why?
>>> 2++2
>>> 2--2
>>> 2+-2
>>> 2-+2
>>> 2++2
>>> 2--2
>>> 2+-2
>>> 2-+2
The tokens and operators here are placed correctly and the calculations are made following
arithmetic rules
2 + (+2) = 4
2 - (-2) = 4
2 + (-2) = 0
2 - (+2) = 0
In math notation, leading zeros are OK, as in 02. What happens if you try this in Python and
why?
>>> 02
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal
integers
It returned an error message indicating a syntax error because leading zeros are not allowed in
Python because of ambiguity
However it can pass as a string when leading zero is put in front of an integer
What happens if you have two values with no operator and a space in between them and
why?
Example :
>>> 1 2
The interpreter displayed an error message indicating a syntax error because Python didn’t recognize
the space between the two values as a valid statement.
Part 2:
Next, describe at least three additional Python experiments that you tried while learning Chapter 1.
Show the Python inputs and their outputs, and explain what you learned from the results of each
example.
1.
>>> 05
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal
integers
05
>>> print("{:02d}".format(5))
05
I learned from this experiment that leading zeros are not allowed but In order to use a leading zero
when it’s in front of an integer, we can pass it as a string or use print("{:02d}".format(1)) for example
(Stack Overflow, 2008).
I tried that format but apparently it works only with numbers from 1 to 9.
2.
>>> print 1
3.
<class 'bool'>
type (true)
Here, I was learning about values and types from Chapter 1 and I typed the same word, which “true”,
once starting with an uppercase letter and once with a lowercase letter. Apparently “True” is a
boolean data type which means that it is one of the built-in data types provided by Python
(GeeksforGeeks, 2020) while “true” with lowercase letter weren’t defined.
References:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
Stack Overflow. (2008, September 25). Display number with leading zeros.
https://stackoverflow.com/questions/134934/display-number-with-leading-zeros