R-Pi - Python - IEEE - 02
R-Pi - Python - IEEE - 02
R-Pi - Python - IEEE - 02
Introduction
RASPBERRY PI AND PYTHON
DAY TWO
2
What is Python Language???
Python is a programming language that lets you work more
quickly and integrate your systems more effectively.
Python is a widely used general-purpose, high-level
programming language.
Its design philosophy emphasizes code readability.
Its syntax allows programmers to express concepts in fewer
lines of code than would be possible in languages such as
C++ or Java.
The language provides constructs intended to enable clear
programs on both a small and large scale.
3
About Python Language
Windows PC
Python’s Consoles Screenshots
5
6
Python Statement
Instructions that a Python interpreter can execute are called
statements.
For example, a = 1 is an assignment statement.
if statement, for statement, while statement are other kinds of
statements.
In Python, end of a statement is marked by a newline
character.
7
Python Statement (Cont.)
But we can make a statement extend over multiple lines with
the line continuation character (\). For example:
a= 1+2+3+\
4+5+6+\
7+8+9
8
Python Statement (Cont.)
Example:
for i in range(1,11):
print(i)
if i == 5:
break
12
Python Indentation (Cont.)
Example - A Example - B
if True: if True: print('Hello'); a = 5
print('Hello')
a=5
14
Python Comments
Comments are very important while writing a program.
It describes what's going on inside a program.
So a person looking at the source code will easily figure it out.
In Python, we use the hash (#) symbol to start writing a
comment.
It extends up to the newline character.
Comments are for programmers for better understanding of a
program.
Python Interpreter ignores comment.
15
Python Comments (
Example:
#This is a comment
#print out Hello
print('Hello')
16
Python Comments (
** Exponent - left operand raised to the power of right x**y (x to the power y)
32
Python Operators – Arithmetic (Cont.)
x = 15
y=4
print('x + y = ',x+y) x + y = 19
print('x - y = ',x-y) x - y = 11
print('x * y = ',x*y) x * y = 60
print('x / y = ',x/y) x / y = 3.75
print('x // y = ',x//y) x // y = 3
print('x ** y = ',x**y) x ** y = 50625
33
Python Operators - Logical
Logical operators in Python
x = True
y = False
print('x and y is',x and y)
print('x or y is',x or y)
print('not x is',not x)
35
Keywords
Keywords are the reserved words in Python.
They cannot be used as variable name, function name or
any other identifier.
They are used to define the syntax and structure of the
Python language.
In Python, keywords are case sensitive.
There are 33 keywords in Python, on next slide
All the keywords except True, False and None are in
lowercase and they must be written as it is.
36
Keywords (Cont.)
The End