PY1
PY1
Lec-1
Today’s Target
Basic about python
Variable, print(), input()
Some basic program
AKTU PYQs
What is python and its features?
Python is a high-level, Features:
1. Simple and Easy to Learn:
general-purpose
2. It is an interpreted language.
programming language that
3. Programs written in Python can run on various
is widely used for various
operating systems like Windows, macOS, Linux, etc.,
applications like web
without any modifications. (Cross platform
development, data science,
compatible)
automation, artificial
4. Python is open-source.
intelligence, and more.
5. Python is dynamically typed, meaning you don't
It was created by Guido van
need to declare variable types explicitly. Python
Rossum and released in
automatically assigns data types at runtime.
1991.
Print ( )
print( ) function prints the
message to the screen or any
other standard output device.
The end keyword is used to
specify the content that is to be
printed at the end of the
execution of the print( )
function.
By default, it is set to “\n”,
which leads to the change of
line after the execution of print(
) statement
Variable
Python Variable is containers that
store values.
Python is not “statically typed”. We
do not need to declare variables
before using them or declare their
type.
The value stored in a variable can be
changed during program execution.
A Variables in Python is only a name
given to a memory location.
Input ( )
This function first takes the input But if we want to input the data of any
from the user and converts it into a other type then we must convert it to
string. that type (type casting/Explicit
The type of the returned object conversion)
always will be <class ‘str’>.
What is dynamic typing? (AKTU 2023-24 EVEN)
KEYPOINTS:
1. The type of the variable is determined when a value is assigned.
2. No need to declare the type of a variable.
3. Variables can store different types of values at different times in the program, this
provide greater flexibility.
ADVANTGES DISADVANTAGES
Ease of Coding: You don't have to Runtime Errors: Errors related to type mismatches
worry about declaring types are only caught during execution (runtime), making
explicitly, making code faster and it harder to catch bugs early compared to statically
easier to write, especially for typed languages.
beginners. Less Explicit Code: Since types are not declared, it
Flexibility: You can reuse the may be harder to understand the intended usage of
same variable for different types variables, leading to confusion and less maintainable
of data, which can be convenient code in large programs.
in certain cases like handling
multiple data types dynamically.
Write a program of swapping of two number(using third
/intermediate/temporary variable ) AKTU 2021-22
Write a program of swapping of two number(without any third variable)
PYTHON
Lec-2
Today’s Target
Type conversion
Data Type
AKTU PYQs By Pragya rajvanshi
B.tech,M.tech
Type conversion
The act of changing an object’s data type is known as type conversion.
Python interpreter automatically The data type is manually changed by the user
converts one data type to another as per their requirement
without any user involvement. There is a risk of data loss since we are forcing
There is no loss of data. an expression to be changed in some specific
data type.
DATA TYPE
Python Data types are the classification or categorization of data items.
A data type defines the kind of values a variable can hold and determines what
operations can be performed on that data.
NUMERIC
Python, numeric data type is used to
hold numeric values.
Int - holds signed integers of non-
limited length.
float - holds floating decimal points
and it's accurate up to 15 decimal
places.
complex - holds complex numbers.
SEQUENCING TYPE
String
The sequence of characters in the
quotation marks can be used to
describe the string.
LIST
List is an ordered collection of similar
or different types of items separated
by commas and enclosed within
brackets [ ].
Tuple
Tuple is an ordered sequence of items
same as a list. The only difference is that
tuples are immutable. Tuples once created
cannot be modified.
we use the parentheses ( ) to store items of
a tuple.
Dictionary data type
Dictionary is an ordered collection of items. It stores elements in key/value
pairs.
Here, keys are unique identifiers that are associated with each value .
Boolean Sets
The Boolean value can be of two Set items are unordered,
types only i.e. either True or False. unchangeable, and do not allow
The output indicates the variable is a duplicate values.
Boolean data.
PYTHON PROGRAMMING
Lec-3
Today’s Target
Operators
Some basic program
AKTU PYQs Pragya Rajvanshi
B.tech,M.tech
Write a program to find out the area and perimeter of Square.
Benefits of python(interpreted , high level, OOP)
Q. How do you read an input from a
Python is interpreted, which allows for easier
user in python to be used as an
debugging and code development.
integer in the rest of the program ?
Python is portable across operating systems and
Explain with an example. (AKTU)
interactive, allowing real-time code execution and
testing.
Python is dynamically typed, meaning you don’t need
to declare data types explicitly.
Python is a high-level language that abstracts low-level
details, making it more user-friendly.
Python is open source.
Ques. In some language every statement ends with semi-colon (;) what
happens if you put a semicolon at the end of python statement
128 64 32 16 8 4 2 1
2 0 0 0 0 0 0 1 0
5 0 0 0 0 0 1 0 1
2&5 0 0 0 0 0 0 0 0
Bitwise or
128 64 32 16 8 4 2 1
2 0 0 0 0 0 0 1 0
5 0 0 0 0 0 1 0 1
2|5 0 0 0 0 0 1 1 1
Bitwise ones' complement Bitwise xor
128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
2 0 0 0 0 0 0 1 0
5 0 0 0 0 0 1 0 1
5 0 0 0 0 0 1 0 1
~5 1 1 1 1 1 0 1 0
2^5 0 0 0 0 0 1 1 1
128 64 32 16 8 4 2 1
5 0 0 0 0 0 1 0 1
5<<1 0 0 0 0 1 0 1 0
Bitwise
left shift
128 64 32 16 8 4 2 1
5 0 0 0 0 0 1 0 1
5>>1 0 0 0 0 0 0 1 0
Bitwise
right shift
Membership operator
Membership Operators are
mainly used in Python to find
whether a value or variable is
present in a sequence (string,
tuple, list, set, and directory).
“In” and “Not In” are the two
membership operators
available in Python.
Membership Operator Description Syntax
Lec-4
Today’s Target
Global and local variable
Operator Precedence and Associativity
Single line block and multi line block
AKTU PYQs
Difference between-
GLOBAL VARAIBLE LOCAL VARAIBLE
Data
It Offers Data Sharing. It doesn’t offers Data Sharing.
Sharing
They are created when the execution of the They are created when the function
Lifetime program begins and are lost when the starts its execution and are lost
program is ended. when the function ends.
Positive, negative,
5 +x, -x, ~x Right to left
bitwise NOT
Multiplication,
matrix, division,
6 *, @, /, //, % Left to right
floor division,
remainder
Precedence Operators Description Associativity
Addition and
7 +, – Left to right
subtraction
Assignment expression
18 := Right to left
(walrus operator)
Solve the following question Solve the following question
a & b << 2 // 5 ** 2 + c ^ b a**2<<2>>b**2^c**3
a=3,b=5,c=10 a=3, b=5,c=10
3&5<<2//5**2+10^5 Precedence 1)**(right to left)
((1) ** (2) // (3) + (4) << (5) & (6)^ 2)<<,>>(left to right)
precedence) 3)^(left to right)
3& 5<<2//25+10^5 3**2<<2>>5**2^10**3
3&5<<0+10^5 3**2<<2>>5**2^1000
3&5<<10^5 3**2<<2>>25^1000
3&5120^5 9<<2>>25^1000
0^5=5 36>>25^1000
(Note a ^0=a and a^1=a’) 0^1000=1000
What will the output of the program (AKTU2020-21)
Questions
Difference between-
Single-line block Multi-line block
Code is written in a single line. Code spans multiple lines with proper indentation.
Might be more challenging to identifying Easier to identify and correct error due to the
and fix error within a single line structured layout