Professional Documents
Culture Documents
Hardware Basics
2
Programming Languages
3
Programming Languages
4
What is Python?
• Created in 1990 by Guido van Rossum
– While at CWI*, Amsterdam
6
Some Features of Python…
• It is a general purpose programming language which can be used for
both scientific and non scientific programming.
7
Some Features of Python…
• Python was developed by taking almost all programming
features from different 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.
• Intel, Cisco, HP, IBM, etc use Python for hardware testing.
10
The first step ...
• Installing python language
– Windows
64-BIT python-3.1x-amd64.exe
» (Run the installer.)
– Linux
$ sudo apt install software-properties-common –y
11
What do you need to write programs in
Python?
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
14
Starting Python
2. Windows
1. From Application Menu,
select Python 3.10 console application
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
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
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
25
Remember …
Variables
Are created when they are first assigned a value
Refer to an object
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
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
29
Built-in Data Types
• Tuples – are identical to lists but are immutable
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”)
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
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
40
Assignment Operators
41
Operators….
42
Bitwise Operators
43
“Order of precedence”
First
not x x and y x or y
Last
44