VJC Chapter 1 Introduction to Python
Uploaded by cheesemuffin · 10 December 2025
Preview
Text from the first pages2022/VJC/JC1/H2Computing/9569 Chapter 1: Introduction to Python Contents 1 Getting started with Python 1.1 Version used 1.2 Platforms for Python programming 2 Starting Python with Hello World 2.1 IDLE 2.2 Python file 2.3 Jupyter Notebook 3 Python Syntax 3.1 Indentation and white space 3.2 Naming conventions 3.3 Write comments Appendix A – Tips for using IDLE Appendix B – Jupyter keyboard shortcuts Appendix C – The Importance of Good Comments: A Tale of the Baker's Apprentice Syllabus Learning Outcomes 2.1 Coding Standards Use common coding standards for programming style (which is dependent on programming language used). 2.1.1 Use indentation and white space. 2.1.2 Use naming conventions (e.g. meaningful identifier names). 2.1.3 Write comments (name of programmer, date written, program description and version bookkeeping/control). References Computational Fairy Tales: The Importance of Good Comments: A Tale of the Baker's Apprentice (computationaltales.blogspot.com) https://www.w3schools.com/python/python_syntax.asp
2022/VJC/JC1/H2Computing/9569 1 Getting started with Python 1.1 Versions used The latest version of Python for Windows is 3.10.1. However, we are using version 3.6.4 for the A-Level H2 Computing Syllabus 9569. 1.2 Platforms for Python programming There are many ways to do programming in Python. 1) One way is to use Python’s Integrated Development and Learning Environment a.k.a. IDLE. It is installed with Python installation. 2) Creating a Python file and run it using IDLE. 3) Jupyter notebook is another platform for Python programming. The version we will be using is 5.5.0. 4) Google Colaboratory. This is a convenient way to do Python programming, as there is no installation of software required. It is a free application available in Google drive. 5) CodeCollab is an online real-time collaborative code editor and compiler. Its web-based application allows users to collaborate in real-time over the internet. It is a powerful editor that supports many other languages on top of Python. https://codecollab.io/ 2 Starting Python with Hello World We will illustrate how to write Python programs using the first three ways mentioned in section 1.2. These three ways are most essential to A-Level H2 computing. Let’s start by printing “Hello World!” 2.1 IDLE The code is simple as such: print("Hello World!") 1. Launch the IDLE app to open a Python shell. Shell is good for experimenting with short expressions or statements to learn new features of the language.
2022/VJC/JC1/H2Computing/9569 2. Type print("Hello World!") in the shell and press Enter. The text “Hello World!” will be displayed. 2.2 Python File When we need to construct complex programs and test them, we can create and save files in program libraries to reuse or share with others. 1. Launch IDLE to open a Python shell. Cilck on the File tab and open a new file in the shell. 2. Enter your code into the file and save the file using .py extention. 3. Run the Python file by clicking on the Run tab followed by Run Module or using the F5 key.
2022/VJC/JC1/H2Computing/9569
2022/VJC/JC1/H2Computing/9569 The output will be displayed in the Python shell. 2.3 Using Jupyter Notebook 1. Open up Windows Powershell 2. Change to d: drive (or the drive with your working files). Type jupyter notebook and press Enter
2022/VJC/JC1/H2Computing/9569 3. Jupyter notebook window will open, displaying the folders/files in the drive. 4. Go to a folder of your choice and start a new jupyter notebook file by clicking on the “new” tab on the top right corner. 5. Click on “Python 3” to start a new notebook file. 6. Change the title of the file to “Hello world”. Type print("Hello World!") and click “Run”. 7. “Hello World!” will be displayed.
2022/VJC/JC1/H2Computing/9569 3 Python Syntax 3.1 Indentation and white space Indentation refers to the spaces at the beginning of a code line. Tab or 4 spaces per indentation level is commonly used. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code. The example above shows that print( ʺ Five is greater than two! ʺ ) is a block of code under the condition if 5 > 2. Python will give an error if indentation is skipped. The number of spaces must be the same in the same block of code. Otherwise, Python will give you an error:
2022/VJC/JC1/H2Computing/9569 That being said, extraneous spaces, tabs and empty lines generally have no effect to the program (except in string literals and for indentation). They should be used adequately and sparingly for readability of the program code. 3.2 Naming conventions Meaningful identifier names should be used to represent a variable, function, class, module and any other object. Look at the code below. Are the variable names meaningful? Can you suggest variable names that are more meaningful than x and y? Python Keywords Python keywords are special words which are reserved and have specific meanings. Python has a set of keywords that cannot be used as variables in programs.
2022/VJC/JC1/H2Computing/9569 Guidelines for Creating Identifiers ● Identifier name can contain following characters ▪ a sequence of letters either in lowercase (a to z) or uppercase (A to Z) ▪ digits (0 to 9) ▪ underscore (_) ● Identifier name cannot begin with digits ● Special characters are not allowed ● Identifier names are case-sensitive (age and Age are different variables) ● Avoid using Python reserved keywords as identifier names Best Practices ● Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability . ● Class names should normally use the CapWords convention. Eg. MyVariableName ● Function, variable, and method names should be lowercase, with words separated by underscores as necessary to improve readability. Eg. my_variable_name ● Constants are usually defined on a module level and written in all capital letters with underscores separating words. Eg. MY_VARIABLE_NAME ● Declare private identifiers by using the single-underscore _ as their first letter. ● Don’t use double-underscores __ as the leading and trailing character in an identifier as Python built-in types use this notation. Which of the following do you think will give an error? 1) message = 'hello' 2) _message = 'hello' 3) 1message = 'hello' 4) message? = 'hello' 5) mes-sage = 'hello'
2022/VJC/JC1/H2Computing/9569 3.3 Write comments Why writing comments is important? Read Appendix C. Comments are additional text within code that provide explanation. Comments can
Content continues in the PDF. Download PDF
Related notes
- NYJC 2026 Prelim P2Exam Papers · 2026
- NYJC 2026 Prelim P1Exam Papers · 2026
- DHS 2026 Y6 H2 Computing Prelim Paper 2_finalExam Papers · 2026
- ACJC 2026 JC2 Computing Prelim Paper 2 (Practical)Exam Papers · 2026
- 2026_NJC Prelim_Computing_P2.pdfExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P2_finalExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_markschemeExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_finalExam Papers · 2026
- 2026 ACJC Prelim Computing Paper 2Exam Papers · 2026
- 2024 ACJC Computing PromoExam Papers · 2024
- 2023 ACJC Promo QPExam Papers · 2023
- 2022 ACJC Computing Promo Paper 2Exam Papers · 2022
- See all H2 Computing notes

