0 ratings0% found this document useful (0 votes) 75 views17 pagesPython Unit 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
SIMPLE AND EASY EXPLANATION
+ NOTES PDF
TOPIC
Introduction to Python: Python variables, Python basic
Operators, Understanding python blocks. Python Data
Types, Declaring and using Numeric data types: int, float
etc.
Engineering Express
PYTHON PROGRAMMING
Introduction to Python: Python variables, Python basic Operators, Understanding python
blocks. Python Data Types, Declaring and using Numeric data types: int, float etc.
Python Program Flow Control Conditional blocks: if, else and else if, Simple for loops in
python, For loop using ranges, string, list and dictionaries. Use of while loops in python,
Loop manipulation using pass, continue, break and else. Programming using Python
| conditional and loop blocks. AwA\X)
Python Complex data types: Using string data type and string operations, Defining list
and list slicing, Use of Tuple data type. String, List and Dictionary, Manipulations Building
blocks of python programs, string manipulation methods, List manipulation. Dictionary
manipulation, Programming using string, list and dictionary in-built functions. Python
Functions, Organizing python codes using functions.
Python File Operations: Reading files, Writing files in python, Understanding read
functions, read(), readline(), readlines(). Understanding write functions, write() and
writelines() Manipulating file pointer using seek Programming, using file operations.
Python packages: Simple programs using the built-in functions of packages matplotlib,
numpy, pandas etc. GU! Programming: Tkinter introduction, Tkinter and
PythonProgramming, Tk Widgets, Tkinter examples. Python programming with IDE.Engineering Express @
| What_is Python?
programming language. It was created by ‘Guido Vam Rossum’ In 1991.
| Python syntax allows program to express their concepts in fewer lines |
of code and let’s as work guickly and intrigued system more
efficiently,
Python in high level language:
According to the basic principle of coding the fact that_make a
|being an_ interpreted language which is not subject to_process, make:
|python a high-level language.
Python is interactive:
is exe is Foll
|key the result will be_printed on the screen _immediately.
Python is object oriented
| oriented programming) approach and often following advantages; _|
Provides a clean program structure,
Python is an object oriented because it is Designed with oops Cobject- || _Engineering Express @
| Facilitates Easy maintenance and modification of executing code. __||__
It supports automatic Garbage collections |
It_can be easily integrated with C, C’*, Java etc.
Python syntax comparison to other programming language:
_« || Python has some similarities with English language with influence |
from mathematics,
Python uses new lines to complete and command. Other language
Step 1
Step 1 —
Run the Application
Run the Application Bt
Step2
Step 2 b
Test the Application
Test the Application
Step 3
Step 3
Edit source code Again
Edit source code Again
step 4
Step 4
Recompile |
Repeat (if needed)
step 5 |
RelinkEngineering Express @
| Python IDE:
PyCharm-
| Jupyter Notebook
| Wing IDE
| Sublime text
Atom
PyCharm:
Interactive python console
__© || Support for web framework
Fast refracting time
|Lesser development
| Jupyter Notebook:
ANN cof wid :
In-built refracting capacity
_|| Sublime text:
Cross platform
Multitasking
| Better customizationEngineering Express @
Atom:
| Better customization
Better uses interfc
: 5
To run a python program e vari described below:
Run on IDLE (integrated Development Environment for Python):-
To run python program_on IDLE, follow the given steps:
Write the python code and save it.
|To run the program, go to Rum>Run Module or simply click FS. _|
|Run_on Command line:
7 | it fil nie \\\, . fl 5
Ai it fi ‘ he
”, -h f File wi |
python script,
bx: / f rh ” Ty .
; ne
[Python hellopy)
|Run on Text Editor:
| Steps are as follows: =
z Ai let “hello.py” 5
the file. To run the code, Right click > select Run code, Else press
‘ctrl talt +N’ to run the code
Input/Output Function in python;
© Output function:
This function help to print or display the output after the
executing line of code.Engineering Express @
We can give one or more arguments and prints them to the __|
tandard output.
| Syntax: print”)
Ex:
printCHello World”)
| Output: Hello World
output: hello world
rintChello worl I
hello world
Input function:
seer LA ov
enter some Text and returns that text_as_a_string. a
BY lecnbt CordnO
Comments:
| Single-line comments:
Created with t.
Used for short explanations on the same line.
Syntax:
BSS esi
line. Chlock) :
Used for longer explanations spanning multiple lines.
|__ Syntax:
Mult-line comment
Python program
>>
Best practices (Advantage of comments):
Provide clarity and context.Engineering Express @
program.
For example: in =
For example: number =10.S
Syntax: variable=expression
zocall ; ;
AY oll asia toaol
NE cei )
; enn ;
and else in return
as except is True
assert finally lambda try
break false nonlocal with
class for None while
continue from not yield
def global or
del if pass
“|| ent import raise
Identifier:Engineering Express @
| Must start with letter Ca-z, A-2) or an underscore (_)
Data types:
Data types are the classification or categorization of data items, It
represents the kindof value that tells what operations can be
performed on a particular data
Data Types in Python
= 3 =o
So be &
| Integer Cint):
Represents whole numbers without decimal points
Example: y=S
Complex(complex):Engineering Express @
| Represents complex numbers with a_re i
Example: 2= 3+4)
Float Coat):
_|| Represents numbers with decimal_points over in exponential form.
| Example: y=3.14
Dicti (dict):
Represents a collection of key-val irs
Example: person= fname’: ‘Alice’, ‘age’ 2S?
Boolean(bool):
Represents either true or false.
TupleCtuple):
Similar to_a_list but immutable (cannot be changed after creation)
Example: coordination= (4,5)
“"NoneTypeCNone);Engineering Express @
| Represents the absence of a value ora null value.
| Type conversion:
Type conversion in_python_is changing the datatype of a variable,
a ion:
Automatic conversion n_ based on the o, ion
Being performed.
Explicit_conversionCcasting):
|IntQ_ for integer conversion.
|Float©)_for float conversion.
StrO_ for string conversion
Loperation will be performed first.
There the various type of expressions are as follows:
Content expression
Arithmetic expression
Integer expression
|| Flight expression
mS bw fe >
Relational expressionEngineering Express @
| Logical expression
_|| operations on operands.
| Assignment operators
Comparison operators
Logical operators
Identity operators
__= ||Membership operators
Bitwise_ operators
+ Ad 442 6
— : Subtraction 4-2 2 ~~ T
—- * Muitiplication 4*2 8 —_
——_r- 1 Division 412 2 —
Modulus operator to get
% remainder in integer division 5%2 1
[ ++ Increment A=10; i
Att —
— -—= Decrement A= 10; 9!
A--
Applying addition between two numbers,
a=l2
| b=10
c=a tbEngineering Express @
| printCc)
| Output: 22
| Assignment operation
Assignment operations are used to_assign the value to variable.
Operator Equals To
+
E
oe
=
a
IF
aes a=a>>10
<2 True
<= Less than or equal to 5<=2 False
>= Greater than or equal to True
= Equal to False
l= Not equal to 5=! True
It compared two value and retum true or false,
Example:
A=!
B=2
print(a==b, a>b, b>a)
output: false false true
Logical operators:
Perform logical operations on Boolean values.
and Logical and (5<2) and (5>3) False
or Logical or (5<2) or (5>3) True
not Logical not not (5<2) True
Identity operators:
It compare the memory location of two objects.Engineering Express
Operator Name Example
is TRUE, if both the variable xisy
points to the same object, with
same memory locations.
is not TRUE, if both the variable xisnoty
points to different objects.
| Example:
|a=S
|b=a
|print(a is b, a is not b)
|output: true false p
| Membership operators:
| Check_if the value is a_member_of a_sequence.
Operator Name Example
in TRUE, if variable is in the list, | xin y
string, dictionary, etc.
not in TRU, if variable isnot inthe | xnotiny
list, string, dictionary, etc.
Example:
a=[),2,3,5]
b=4
print(b in a, b not in a)
output: false true
Bitwise_operators:Engineering Express
Perform operations on individual bits of binary numbers.
Operator Meaning
& Bitwise AND
I Bitwise OR
“ Bitwise exclusive OR / Bitwise XOR_
~ Bitwise inversion (one’s complement)
<< Shifts the bits to left / Bitwise Left Shift
>> Shifts the bits to right /Bitwise Right Shift
Lxarnple: 4 TN a
a=3 LZ La \ Se ah.
b=?
|print(a & b, ~a) Sa. = a
loutput: 3 4
___Python Operator Precedence ay
Precedence ign | Operator Name
Highest Exponentiation
‘Unary positive, unary
negative, bitwise negation
Multiplication, division, fo
dlivision, modulus
ie Addition, subtraction
-shift,right-shift
& Bitwise AND:
x ‘Bitwise XOR
1 Bitwise OR
= a
is,isnot
not Boolean NOT
Comparlson, identity
ay ‘a, i eee!Engineering Express @
Determine the order of execution for operators with the same
| precedence.
There are two type oi ociativity:
L ight:
first the move towards_right.
|__2. Right to Left:
Operators of the same precedence are executed from the right
| Example
|a=3+2-]
| printCa)
output: 4
Operators of the same precedence are executed from the left side ||Engineering Express: Simplifying Engineering Education
‘Are you drowning in complex engineering concepts? Struggling to decipher cryptic notes? Fear not! Welcome to
Engineering Express, where we decode the mysteries of engineering subjects for you. §P
What We Offer:
Clear Explanotions: Our notes break down intricate topics into bite-sized, easy-to-understand language, No jargon,
no headaches!
Real-Life Connections: Ever wondered how those abstract formulas apply in the real world? We've got you covered
with relatable examples.
Maximize Your Marks: Our mission? Boost your exam scores. With our straightforward notes, you'll be well-
prepared to conquer any engineering challenge.
Follow us on social media
YouTube - https://www youtube.com/@Engineering Express. ?sub_contirmation=I
WhatsApp - https://chat.whatsapp.com/H]6tpUl2SmQ3o6vleD2Dlu
Instagram - https://www.instagram.com/engineeringexpress2 312/
Telegram - https://t.me/engineeringexpressofficial
Join the Engineering Express community today ond unlock the power of simplified learning! <7 @