You are on page 1of 44

An Introduction

Hardware Basics

2
Programming Languages

3
Programming Languages

4
What is Python?
• Created in 1990 by Guido van Rossum
– While at CWI*, Amsterdam

• The language was released in 1991.

• The name “PYTHON” was from a late 70’s tv show “Monty


Python’s Flying Circus”.

• Python is a general purpose programming language.

* Centrum Wiskunde & Informatica (CWI), is a National Research Institute for


Mathematics and Computer Science in Netherlands.
5
The Creator…

6
Some Features of Python…
• It is a general purpose programming language which can be used for
both scientific and non scientific programming.

• It is a very simple high level language with vast library of add-on


modules

• It is excellent for beginners as the language is interpreted, hence gives


immediate results.

• The programs written in Python are easily readable and understandable.

• It is suitable as an extension language for customizable applications.

• It is easy to learn and use.

7
Some Features of Python…
• Python was developed by taking almost all programming
features from different languages

– Functional Programming Features from C

– Object Oriented Programming Features from C++

– Scripting Language Features from Perl and Shell Script

– Programming Features from Modula-3

– Most of syntax in Python Derived from C and ABC languages.

8
Where can I use Python?
 For developing Desktop Applications
 For developing web Applications
 For developing database Applications
 For Network Programming
 For developing games
 For Data Analysis Applications
 For Machine Learning
 For developing Artificial Intelligence Applications
 For IOT
 …….
 Internally Google and Youtube use Python coding NASA and
Nework Stock Exchange Applications developed by Python.

9
Who is using Python?
• In operations of Google search engine, youtube, etc.

• Bit Torrent peer to peer file sharing is written using Python

• Intel, Cisco, HP, IBM, etc use Python for hardware testing.

• Maya provides a Python scripting API

• i–Robot uses Python to develop commercial Robot.

• NASA and others use Python for their scientific programming


task.

10
The first step ...
• Installing python language

– Windows

Download python from www.python.org 

64-BIT  python-3.1x-amd64.exe
» (Run the installer.)
– Linux
$ sudo apt install software-properties-common –y

$ sudo add-apt-repository ppa:deadsnakes/ppa

$ sudo apt update; sudo apt install python3.11-full –y;

All major Linux versions have python pre-installed.

11
What do you need to write programs in
Python?

• An interpreter to translate and execute your program

• A text editor for writing and changing your source


code
– Notepad is possibly useful but not really suited to
programming
– More advanced editors can:
• Automatically indent the code
• Color code to clarify its meaning
• Jump from variable name to its definition
• Jump from function call to its definition
• Much more…

12
Integrated development
environments
• An IDE (integrated development environment)
combines several programming tools together into one
cohesive program.
• Some IDEs for Python:
– IDLE comes with Python – it’s installed when Python is.
– PyScript, PyCharm are a couple other IDEs that you can find for free.
– PyDev with Eclipse
– MS-VS-Code
– MS-Visual Studio 2019 for Python
– Anaconda
– Fedora Python Classroom
– Jupyter Notebook
– Thonny
– And Many More……..

13
Starting Python
1. Linux
1. Logon to linux as a user, open the terminal and type
1. $ python3.11

2. idle-python3.11 from program menu

14
Starting Python
2. Windows
1. From Application Menu,
select Python 3.10 console application 

2. Select the IDE from Application menu 

15
Jupyter-notebook
• The Jupyter Notebook is an open-source web application
that allows you to create and share documents that contain
– live code,
– equations,
– visualizations and narrative text.
– Uses include:
• data cleaning and transformation,
• numerical simulation,
• statistical modeling,
• data visualization,
• machine learning,
• and much more…….

16
Installing Jupyter
• Open the command prompt with Administrative Privileges
and run the following command
pip install jupyter

• After installation completes, run the following command to


open the notebook

jupyter notebook

17
Starting Jupyter-notebook

18
The Philosophy of Python

19
Comments

20
Storing & Computing Data
• What data might we want to work with?

1001
“Oranges”

3.22 * 148
3.14 * 99

“Learning Python 3”

21
Variables…
 Have
Identity
Variable’s Address in Memory
Once created does not change
Id  id() prints the identity number of a variable

Type
Data type of the variable
Type  type() prints the data type of a variable

Value
Information stored

22
Variables

• Variables in Python are dynamically-typed:


– declared without an explicit type,
– objects have a type,
so Python knows the type of a variable, even if you don't

23
Variables…..

24
Mutable and Immutable
• Variables can be mutable or immutable

Mutable
one whose values may change in place
Immutable
change of values will not happen in place

modifying an immutable variable will rebuild the same


variable

25
Remember …
Variables 
 Are created when they are first assigned a value

 Refer to an object

 Must be assigned a value before using them in any


expression

 Keywords cannot be used as variable names

26
Expressions
• An expression represents something
– Python evaluates it (into a value)
– Similar to a calculator

Example:
• 3.14 Literal (evaluates to self)

• 4 * 7 – 9 * 0.2
Expression with four literals and some
operators
• ( 3 * 2 + 11 ) * 2

27
Types
• A set of values & operations on these values
• Operations : + - * /
• Meaning of operations depends on type

• How to tell the Type of a value


Command: type(<value>)

28
Built-in Data Types
• Numeric – simple numbers, can be
– float (64bits)
• Range 
– 2.22507×10−308 --to-- 1.79769×10+308
– complex
– int
• Boolean (bool) – is used to represent True or False

• String (str) – text or alpha-numeric data

• List – a collection of other objects – floats, integers,


complex numbers, strings or other lists

29
Built-in Data Types
• Tuples – are identical to lists but are immutable

• Dictionary – are composed of keys(words) and


values(definitions)

• range() – creates a sequence of numbers

30
The print() method
Prints the given text message or expression value on the console, and
moves the cursor down to the next line
Syntax:
print(*objects, sep' ', end='\', file=sys.stdout, flush=false)

objects - object to the printed. * indicates that there may be more than one object
sep - objects are separated by sep. Default value: ' '
end - end is printed at last
file - must be an object with write(string) method. If omitted it, sys.stdout will be used
which prints objects on the screen.
flush - If True, the stream is forcibly flushed. Default value: False

31
The print() method
Examples:
#prints the text to console
>>> print(“Working with Python”)

#print variables and literals to console


>>> name = “James Gosling”
>>> age = 66
>>> print(“Name is : {0}, Age is : {1}”.format(name, age))
OR
>>> print(“Name is : %s, Age is : %d” % (name, age))
OR
>>> print(“Name is : “ , name, “\n Age is : “, age))
OR
>>> print(“Name is “, name, “\n Age is “, age, sep=“#”)
OR
>>> print(“Name is “ + name +“\n Age is “ + age)

32
Special Characters
Sequence Meaning Example
\’ Single Quote print(“ Daddy\’s Day Out ”)
\a Bell print(“ Hello Python \a “)
\n New Line Feed print(“ Welcome to \n Python “)
\f Form Feed print(“ Welcome to Python \f ”)
\b Backspace print(“ Welcome to Python\b ”)
\t Horizontal Tab print(“ Welcome to \t Python “)
%c Single Character char=“X”
print(“ %c “ % char)
%s String name=“Bill Gates”
print(“ %s “ % name)
%d or %i Integers x=109
print(“ %d %i “ % (x, x + 10))
%f Float, Double x=99.9999911111
print(“ %f “ % x )

33
Some more on text…
• Python supports “UniCode” characters.
• Unicode characters begin with a “\u” followed by
hexadecimal (base16) representation of a character.

Reference  “http://www.unicode.org/charts/”

34
Supported Data Types

35
Arithmetic Operators
Symbol Description Example 1 Example 2
>>>55+45 >>> ‘Good’ + ‘Morning’ GoodMorning
+ Addition
100
>>>55-45 >>>30-80
- Subtraction
10 -50
>>>55*45 2475 >>> ‘Good’* 3 GoodGoodGood
* Multiplication

>>>17/5
3.4 >>>28/3
/ Division
>>>17/5.0 3.4 9. 333333333333334

Remainder/Modulo >>>17%5 >>> 23%2


%
2 1
>>>2**3 >>>2**8
** Exponentiation 256
8
>>>7.0//2 >>>3// 2
// Integer Division
3.0 1

36
Relational Operators
Symbol Description Example 1 Example 2
>>>7<10
True >>>‘Hello’< ’Goodbye’ False
>>> 7<5 >>>'Goodbye'< 'Hello'
< Less than False True
>>> 7<10<15
True
>>>7>5 >>>‘Hello’> ‘Goodbye’
True True
> Greater than >>>10<10 >>>'Goodbye'> 'Hello' False
False
>>> 2<=5 >>>‘Hello’<= ‘Goodbye’
True False
<= less than equal to >>> 7<=4 >>>'Goodbye' <= 'Hello'
False True
>>>10>=10 >>>’Hello’>= ‘Goodbye’
True True
>= greater than equal to >>>10>=12 >>>'Goodbye' >= 'Hello' False
False
>>>10!=11 >>>’Hello’!= ‘HELLO’
True True
! =, <> not equal to >>>10!=10 >>> ‘Hello’ != ‘Hello’ False
False
>>>10==10 >>>“Hello’ == ’Hello’
True True
== equal to >>>10==11 >>>’Hello’ == ‘Good Bye’ False
False
37
Logical Operators
Symbol Description
Or
If any one of the operand is true, then the condition becomes true.
And
If both the operands are true, then the condition becomes true.
Reverses the state of operand/condition.
Not

38
Assignment Operator
Symbol Description Example Explanation
>>>x=12* *we will use it as initial
Assigned values from right side operands to
= >>>y=’greeting value of x for following
left variable
s’ examples.
Added and assign back the result to left Will change the value of x to
+= >>>x+=2
operand 14
Subtracted and assign back the result to left
-= x-=2 x will become 10
operand
Multiplied and assign back the result to
*= x*=2 x will become 24
left operand
Divided and assign back the result to
/=
left operand x/=2 x will become 6
Taken modulus using two operands x will become 0
%=
and assign the result to left operand x%=2
Performed exponential (power) x will become 144
**= calculation on operators and assign value to x**=2
the left operand

Performed floor division on operators x / /= 2 x will become 6


//=
and assign value to the left operand
39
Precedence of Operators
Operator Description

** Exponentiation (raise to the power)

+,- unary plus and minus

Multiply, divide, modulo and floor


* , /, %, //
division
+,- Addition and subtraction
relational operators for
<, <=, >, >= comparision
==, != Equality operators

%=,/ =, //=, - = , + =, * = , ** = Assignment operators

not; and; or Logical operators

40
Assignment Operators

41
Operators….

42
Bitwise Operators

43
“Order of precedence”
First

x**y -x +x x%y x/y x*y x-y x+y

x==y x!=y x>=y x>y x<=y x<y

not x x and y x or y

Last
44

You might also like