In your terminal window type python to start an interactive Python environment. (Note that if you are using Ubuntu and are not running a virtual environment, then to run Python type python3.)
$ python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
The >>> is the prompt where you type your code. Within the Python interactive shell you can evaluate expressions. Try doing some arithmetic like this:
>>> 1 + 2
3And use the print() function:
>>> print("Hello Class")
Hello Class- Variables hold values. They are strings containing only letters, numbers and underscores
"_". They cannot start with a number. - It is best to use descriptive names
- Python's convention for variables is to use underscores between words such as
secret_coderather than camel case such asSecretCode. (Camel case, on the other hand, is used for class names.)
Note that even though it is not required, it is important to follow Python's conventions, such as the above for variable names, as this makes your code much more readable and understandable to others and to yourself.
>>> student_age = 19
>>> student_age
19
>>> print(student_age)
19Judicious comments within your code can greatly improve understanding of your code for others and yourself at a later date.
- Block comments: A newline starting with a
#. - Inline comments: A
#will comment out the rest of the line.
Conventions:
- Write complete sentences
- Use at least 2 spaces before an inline
# - Use a single space after the
# - Don't describe what is already obvious
- Ex: if you have the line
number_of_cars = 5, don't add a comment# Number of cars
- Ex: if you have the line