INTRODUC
TION TO
PYTHON
Part 1
2
Roadmap Variables,
What is Literals, Data
Python? First Program Types
1 3 5
2 4 6
Download Rules for Input in
Python Identifiers python
And
comments 3
CODING
Coding (more formally known as Computer
Programming) is writing instructions for a
computer to perform a task. This code has to be in
the form that the computer understand.
Some examples of Programming Languages
Python
SQL
Java
Fortran 4
What
is
Python
?
Python is a programming language
that lets you work quickly and
integrate systems more effectively.
This makes writing short programs
fast and you can produce almost
5
anything you can imagine
Applications of python
1. Web Development
2. Game Development
3. Machine Learning
4. Mathematics
5. Education: Python is a superb language for
teaching programming, both at the introductory
level and in more advanced courses.
6. Desktop GUI
7. Software Development: Python is often used
as a support language for software developers,
for build control and management, testing, and
in many other ways.
8. Operating System
9. Artificial Intelligence
10.Internet of Things (IoT) 6
Download
Python
https://www.python.org/downloa
ds/
7
Where to use python online
▪ Ideone : https://ideone.com/
▪ GBD compiler:
https://www.onlinegdb.com/
▪ Google Colab:
https://colab.research.google
.com/
And many more...
8
Our first python code
Type the following code into the editor:
print("hello world")
Click Save to save the program.
Enter the file name helloworld and click the
Save button
9
Hello
World!
My first program in python
10
Code
print(“hello world!”)
11
Making mistakes
Syntax refers to the structure of
statements or the arrangement of codes in
a computer language.
Syntax Errors are mistakes in the source
code, such as spelling and punctuation
errors, incorrect labels, and so on, which
cause an error message to be generated by
12
Making mistakes
Which of these lines of code are correct?
Print (“Hello World!”)
print (“Hello World!”)
print (Hello World)
Print (Hello World)
print “Hello World”
13
TEXT, MATHS
AND LOOPS
▪ Learn how to do some more with
text
▪ Get Python to do some maths for
you
▪ Learn about how while loops work
▪ Learn lots of useful operators
14
ESCAPE
SEQUENCE
An Escape sequence : is a set of
characters which has special meaning
when it is used inside a string(text). The
characters need to be preceded by a
backslash
15
ESCAPE
SEQUENCE
print (“Question: What is a thief of time? \n
Answer: Procrastination is a thief of time.”)
Escape What it does
sequence
\n Create a line return in a string of a text
\t Create a tab style indent in a string of text
\\ Allow backslash to appear in a string of text
\” Allows a speech mark to be used in a string of text
16
Escape Description Example Output
Sequence
\n Create New line/move Print(“hello\n Hello
to new line world”) world
\t Horizontal line (create Print(“hello\t Hello world
space) world”)
\’ Single quote Print(“hello \’world\’ Hello ‘world’
”)
\” Double quote Print(“hello \”world\ Hello “world”
” ”)
\\ Backslash Print(“hello \\ hello \world
world”)
Functions
A function is a block of code which only runs when
it is called. For example print () is a called
function.FUNCTION DESCRIPTION
pow() Returns the value of x to the power
of y
all() Returns True if all items in an
iterable object are true
float() Returns a floating point number
input() Allowing user input
int() Returns an integer number
maths
Python can be used to perform simple calculations
as well as complex calculations.
Operator Name Example Answer
+ add 3+1 4
- subtract 2-1 1
* multiply 5*2 10
/ Divide(normal) 20/8 2.5
// Divide(integer) 20//8 2
% modulus 20%8 4
COMBINING TEXT AND
MATHS
It is also possible to combine text (strings) and
numbers in the
print() function. The comma (,) is used as a separator
between the
text and the math.
1. print(“100 divided by 5 =”, 100/5)
2. print(“90 plus 11=”, 90+11)
COMBINING TEXT AND
MATHS
What will be the output for this code?
print(“11 divided by 4 also equals:”,11/4,
“remainder:”,11%4)