0% found this document useful (0 votes)
3 views55 pages

Introduction To Python Handmade

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views55 pages

Introduction To Python Handmade

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Introduction to Python

Presented by
Vibhav Ambardekar, PhD

1
Installation of python
• Download Python | Python.org,
https://www.python.org/downloads/date accessed on: 03/08/2025

2
What are the various IDEs for Python
1. Pycharm
2. Spider
3. Ginny
4. Visual Studio Coade
5. Jypyter Notebook
6. IDLE
7. PyDev
8. Thonny
9. PyScripter
Anaconda Navigator is a Graphic User Interface (GUI) that simplifies the process of managing packages, environments, and
applications for data science. It is included in the Anaconda Distribution and is available for Windows, macOS, and Linux.

Advance AI with Open Source | Anaconda, https://www.anaconda.com/, date accessed on: 03/08/2025 3
Few IDEs for python: IDLE

4
Pycharm

5
Anaconda Navigator

6
Jupyter notebook

7
Getting Started….

8
Welcome to the Jupyter notebook

9
Variables in Python
• A python identifier is a name that is used to describe variables, functions,
characters, or any other user defined items
• Python is a case sensitive programming language, i.e. Sale and sale are two
different identifiers in python
• The name of the identifier must follow the naming rules
• The name of an identifier may be composed of letters, digits or underscore
characters
• An identifier starts with A to Z or a to z or an underscore (_) followed by
digits (0 to 9)
• Python does not allow punctuation characters (@,%,$) within the identifiers
• Some words are reserved words like if, else, while, for, continue, break, etc.
• These reserved words cannot be used as constants or other identifier names

10
Assigning values to variables
• An identifier is usually associated with an expression or value
• = represents an assignment operator and it does not relate any
mathematical quantity
• x=5 means value of 5 is assigned to variable x or value of 5 is stored
into variable x
• Numeric value is written without double quotes and a string is always
written in double quotes
• Country=“India” represents that the string value of India is stored in
the Country variable
• String represents a set of characters which are immutable

11
Basic Operations
• Numbers
• 1,2,3,4,5…10 represent integers
• 10.5, 11.9.3.14, 10E-12 represent floating point numbers
• 2+3i, 7-3i represent complex number
• Arithmetic overflow: multiplication of two floating point numbers results into a number of very
large magnitude (2.7e20*4.3e20) to be represented
• Arithmetic underflow: division of two floating point numbers results into a number of very small
magnitude to be represented
• Loss of precision problem: 1/3 gives 0.33333333 where 3 is repeated inflnitely. Ultimately, we take
it as 0.33 (usually upto two decimal places)
• Python automatically displays rounded results to keep the number of digits displayed manageable
• For scientific computation, rounded results may impact to great extent

12
Built in functions
• Any floating-point value contains an arbitrary number of decimal
places.
• Use of built in function is recommended to produce a string version of
a number with required number of decimal places

13
Simple operations on numbers

The spaces around plus and minus signs are optional. They are usually provided to make the code readable! 14
Strings in python
• A string is a group of characters
• When there is a need to use text in python, string is used
• A string is represented in quote marks ‘-‘, ‘’-‘’, ‘’’-’’’
• We can print a string without using print function provided we use it correctly

String literal concatenation


• Python concatenates two strings which are placed apart as shown

15
Escape sequence
• Some characters (like ", \) cannot be directly included in a string

16
Strings formatting

< symbol means to left justify


>symbol means to right justify
^ symbol means to align the string

17
Assigning or initializing values to variables
• In Python, programmers need not explicitly declare variables to
reserve memory space.
• The declaration is done automatically when a value is assigned to the
variables using ‘=‘ sign variable.
• The operand on the left side of equal sign is the name of the variable
and the operand on the right side represents value to be stored in
that variable

18
Assigning or initializing values to variables

19
Operators and Expressions in python
Arithmetic operators

20
Comparison operators or relational operators

21
Assignment In Place or Shortcut Operators

22
Commands to show the application of +- characters
on string

23
Unary Operators
• Unary operators act on single operands.
• Python supports unary minus operator.
• Unary minus operator is strikingly different from
the arithmetic operator that operates on two
operands and subtracts the second operand from
the first operand.
• When an operand is preceded by a minus sign, the
unary operator negates its value.
• For example, if a number is positive, it becomes
negative when preceded with a unary minus
operator.
• Similarly, if the number is negative, it becomes
positive after applying the unary minus operator.
Consider the given example.

24
Bitwise operators
• bitwise operators perform operations at the bit level
• Bitwise AND, bitwise OR, bitwise XOR, and shift operator
Bitwise AND (&)
Truth table for bitwise operators
1010101010 & 0101010101=0000000000

Bitwise OR (|)
10101010 | @1010101 = 11111111

Bitwise XOR (^)


10101010 * 91010161 = 11111111

Bitwise NOT (~)


~1001 =0110

25
Logical Operators
• logical AND (&&), logical OR (||), logical NOT (!)
For logical AND, If we have an expression( a>b) && (b>c), then the whole expression is true only if both
expressions are true. That is, if b is greater than a and c.

For logical OR, If we have an expression( a>b) || (b>c), then the whole expression is true only if either of two
expressions are true. That is, if a is greater than b or b is greater than c.

The logical not operator takes a single expression and negates the value of the expression. Logical NOT
produces a zero if the expression evaluates to a non-zero value and produces a 1 if the expression produces
a zero. In other words, it just reverses the value of the expression.

A=10, b,
b = !a;
Now, the value of b = 6. The value of a is not zero, therefore, !a = 0. The value of !a is assigned to b,
hence, the result.

The truth table for logical operators is exactly same as that of bitwise operators 26
Operators Precedence and Associativity

Operator precedence table is important as it affects how an expression is


Boolean data types
evaluated

27
Operations on Strings
String concatenation

28
Multiplication (or String Repetition)

29
Program for addition and multiplication on
string variables

30
Slicing of a string

31
Other data types in python
• list
• tuples
• dictionary

A list consists of items separated by commas and


enclosed within square brackets([])
The difference between a list and an array is array
consists of values of same data type whereas list may
have values of different data types

32
Dictionary
• It stores data in key value pairs
• The key values are usually strings and value can be of any data type
• The key value pairs are enclosed with curly braces ({ }).
• Each key value pair is separated from other using colon sign (‘:’)
• To access the value in a dictionary, you need to specify its key value in
square braces
• Dictionaries are used for fast retrieval of data

33
Type Conversions

34
Decision control statements
• The decision control statements usually jumps from one part of the code to
another depending on whether a particular condition is satisfied or not
• they allow you to execute statements selectively based on certain decisions.
• Such type of decision control statements are known as selection control
statements or conditional branching statements
• Python language supports different types of conditional branching
statements which are as follows:
a) If statement
b) If-else statement

35
If statement

False
Test
expression

True

Statement block 1

Statement x

36
Examples of if statement

37
If-else statement
True False
Test
expression

Statement block 1 Statement block 2

Statement x

38
If-else statement example

39
Nested if statements
• A statement that contains other statements is called a compounds
statement
• Nested if statements are used to deal with more complex checks
• If statements are placed one inside the other
• Nested if statements are used to check whether more than one
condition is satisfied

40
Example for nested if statements

41
If-elif-else statement
• It works in the same way as if else statement
• It is also called nested-if construct
• The elif statement is shortcut to the if and else statements

Test
expression 1

Statement block

42
If-elif-else statement example

43
Iterative statements
Python uses iterative statements that are used to repeat the execution of a list of statements

• The for loop


• The while loop

44
The while loop
• The while loop provides a mechanism to repeat one or more statements while a particular condition is true

Statement x

Update the condition expression


Test
expression 1

True
Statement block
False

Statement y

45
The while loop examples

46
The for loop

Specify the range of sequence

Test True
Statement block 2
expression 1

False

Statement block 2

47
The for-loop examples

end followed by quote marks having some space between them is used provide space between the
numbers which are getting printed as shown above 48
The for-loop examples

49
Key points to remember
• If range function is given in a single argument, it produces an object with values between 0 to argument -1
• For example, range(10) is equivalent to writing range (0,10)
• If range has three arguments, the third argument shows the step size or an interval of the result produced.
• The third argument must be an integer
• For example, range(1,20,2)

50
The break statement
• The break statement is used to terminate the execution of the nearest
enclosing loop in which it appears
• It is widely used for while-loop and for-loop
• When the break statement appears in the program, the control
passes to the statement that follows the loop in which the break
statement appears

51
The continue statement
• Like break statement, the continue statement can only appear in the
body of a loop
• When a compiler encounters a continue statement, then the rest of
the statements in the loop are skipped and the control is
unconditionally transferred to the loop-continuation portion of the
nearest enclosing loop

52
The pass statement
• It is used when a statement is required syntactically but the command
or code has to be executed
• It specifies null operation or simply no operation statement

53
References
• Reema Thareja - Python Programming - Using Problem Solving
Approach-Oxford University Press, India (2017)
• For this ppt refer chapter 3_basics of python programming and
chapter 4_decision control statements

54
Thank You!!!

55

You might also like