Python
INTRODUCTION TO
PYTHON
• Python is a text-based programming while Scratch is a block-based
programming
• Python requires to remember different syntax (code) that is needed
• Python is normally installed with an Integrated Development and
Learning Environment (IDLE)
print(“Hello World”)
Python
Variable
• Python can operate in two modes:
• Variable is memory location used to store a value; the value of data can
be changed during program execution
• Constant is a named memory location used to store a value; the value
can be used but not changed during program execution
• In many computer languages, the data type must be provided when
declaring or initialising variables
• Interactive mode
• Script mode
• Adding comments to code to provide extra information about the code
• In Python, this can be done by starting the comment with a # symbol, any
text on a line after a # symbol will be ignored
Types of Data
• Data type is a specification of the kind of value a variable will store
• Examples of data type are:
• Integer
• Real
• Char
• String
• Boolean
Variable
name = “Ardeel”
print (name)
print (“Your name is ”, name)
age = 12
print (age)
age = age + 2
print (age)
Types of Data
Data Type
Description
type(variable)
Integer
Whole number
(1, 2, 3)
‘int’
Real
Fractional value, decimals
(1.1, 9.0)
‘float’
Char
Single character or symbol ‘str’
(A, z, &, 6)
String
More than one character
(Hello)
‘str’
Boolean
One of two values
(TRUE, FALSE)
‘bool’
Arithmetic Operators
Operation
Example in Python
Example of Result
Addition
result = num1 + num2
6+2=8
Subtraction
result = num1 - num2
6-2=4
Multiplication
result = num1 * num2
6 * 2 = 12
Power of
result = num1 ** num2
6 ** 2 = 36
Division
result = num1 / num2
6/2=3
Integer Division
result = num1 // num2
7 // 2 = 3
Modulus
result = num1 % num2
7%2=1