Saturday, 9 September 2017

A New Blog with Good Intentions

The basics of this blog is that I am a novice programmer learning about Python, and I thought it would be interesting (and maybe unintentionally amusing) for others to see how I get on.

A bit about me:
  • I am studying Computing and IT at the Open University
  • I live in the UK
  • I am 44 years old (yes, quite old for a student, actually in the process of changing careers)
  • I am quite geeky, enjoying Sci-Fi, Fantasy, dinosaurs, natural history and military history
My current programming environment is:
  • Windows 10 on a desktop as OS
  • IDLE as shell/environment
  • Python 3.5 as current version
So, on with the code. Rather than typing straight into the IDLE command line, I generally create .py files, save them and use F5 to run, even for very small scripts, mainly because I never know whether or not I will want to look back later and see how I did something. Another thing, an oddity left over from when I was using Linux, is I often start Python scripts with
#!/usr/bin/python
This means should the script find itself on a Linux system, it has a chance of actually running (that line is ignored by the Python interpreter but tells the Unix shell what program is used to run it). 
As I save my Python scripts to my Dropbox folder, crossing between operating systems is a possibility. 
Note to self - ought to start changing that header to
#!/usr/bin/python3
When I was first looking at Python on Linux, I used the default version, which is Python 2.7. Then I switched to Windows and downloaded IDLE and Python for Windows - that shifted me unexpectedly to Python 3.x - mostly the same but with enough differences that I need to be careful which script is for which version. 

So here is the first script of the blog:
#!/usr/bin/python
# comments here
print ("Hello World")
Very simple. About as minimal as you can get. And the output is traditional for first programs.
Note that in Python  the hash sign # is for comments, and anything after it on the same line is not interpreted by Python.
Also print in Python 3.5 requires round brackets (parentheses)
 The results when I run it in IDLE are:
>>>
 RESTART: C:\Users\John\Dropbox\Misc Programming\Python\python3\test01_hello_world.py
Hello World
>>>
 It works!!

No comments:

Post a Comment