You are on page 1of 4

Topic 02 – Programming and Development

NOTE – REVISION - PART I

Programming in Python
What is Python?
❖ Python is a general-purpose programming language created in 1991 by Guido Van Rossum.
❖ It is an interpreted, interactive, object-oriented, beginner's programming language.

What is a variable in Python?


❖ In any programming language, variables and other data structures are reserved memory locations to
store data within the execution time of a program.
❖ They are created in the main memory (RAM) of the computer that executes the program.
❖ Once the program is finished, the data structures created and used within that program will be lost.

What is a comment in Python?


❖ In any programming language, there is a thing called a ‘comment’ where we can type anything as text
without affecting the program code.
❖ In Python, we can type a comment starting with a # symbol. After #, any character you type in the
same line will be considered as a comment.
❖ Comments will not be considered when the program code is executed in a computer.
❖ Comment in Python can be used to:
1. To describe the things we do in our code.
2. To hide code lines without deleting them or getting them executed.

How to create variables and assign values to variables?


❖ Unlike in some other programming languages like Java or C#.net, creating data structures in Python is
easy.
❖ In Python, we do not need to specify the data type of the data structure that we create.
❖ But we must give a proper name for the data structure when creating.
❖ Remember not to use spaces to separate words in the same variable name. You can use the
variable naming methods that we discussed in Topic 01.
❖ Usually, we can create variables when we are ready to assign the first value to it.
o Example 01: How to create a variable in Python.

Monday, October 17, 2022 Page 1 of 4


Topic 02 – Programming and Development
NOTE – REVISION - PART I
o Example 02: How to assign different types of values to variables.

What are operators in Python?


❖ Operators are special symbols that can perform mathematical calculations, logical comparisons,
or value assignments.
❖ Typical Operation:

What are Arithmetic Operators in Python?


❖ Arithmetic Operators are the symbols we can use to perform mathematical (arithmetic) calculations
in Python.

Monday, October 17, 2022 Page 2 of 4


Topic 02 – Programming and Development
NOTE – REVISION - PART I
What are Comparison Operators in Python?
❖ Comparison Operators are the symbols we can use to create logical conditions in Python.
❖ A logical condition is made up of two operands, left operand and right operand.
❖ So, comparison operators are used to compare two operands and decide whether the condition is
TRUE or FALSE.

How to read user input from the keyboard in Python?


❖ We can use the input() function to read keyboard input from the user.
❖ By default, the value taken using the input() is of type string.
❖ If we need to convert that string value into a numeric value (for calculations), we can use int() and
float() functions.
o Example:

Monday, October 17, 2022 Page 3 of 4


Topic 02 – Programming and Development
NOTE – REVISION - PART I
Revision – Part I – Exercises
Write Python programs for the following questions

Q1. Sequence Control Structure I


Ask the user for his/her name and age. After he/she enters those details, Display a message according to
the following format.
Example: (Text colored in red are example user input values)
Please enter your NAME: Thehansa
Please enter your AGE: 15
=====================================================
Your name is ‘Thehansa’ and you are ’15’ years old.

Q2. Sequence Control Structure II


Ask the user to input 3 numbers. Then display the average value of the inserted 3 numbers.
Example: (Text colored in red are example user input values)
Please insert FIRST NUMBER: 30
Please insert SECOND NUMBER: 30
Please insert THIRD NUMBER: 60
=====================================================
AVERAGE of inserted values: ‘40’

Monday, October 17, 2022 Page 4 of 4

You might also like