m1 Python Notes
m1 Python Notes
m1 Python Notes
Presented By
S.SENTHIL
AP/CSE
K.RAMAKRISHNAN COLLEGE OF TECHNOLOGY
COURSE OUTCOMES
CO1- Apply the Python fundamentals to solve elementary problems.
CO2-Demonstrate the use of Control Statements and Functions for efficient
program flow and modularity.
CO3-Perform various operations in strings, list and tuple.
CO4- Demonstrate the different methods in Dictionary, Set and Regular
Expression.
CO5-Integrate the knowledge of Python syntax, libraries, and frameworks in
building applications
Text Book:
Anurag Gupta, IPS Jharkhand, GP Biswass, “ Python
Programming, Problem Solving, Packages and
Libraries”,McGraw Hill Education(India) Private Limited, 2019
ISBN-13:978-93-5316-800-1
“Python Programming: Using Problem Solving Approach “ by
Reema Theraja, Oxford Higher Education,2017.
Gowrishankar S, Veena A, “Introduction to Python
Programming”, 1st Edition, CRC Press/Taylor & Francis, 2018.
ISBN-13: 978-0815394372
Module-1
Python Basics, Data Types, Expressions and
Operators
Python Basic Concepts: Interactive Mode and Script Mode -
3.Executing the Script: To run the script, you open a terminal or command prompt, navigate
to the directory where the script is saved, and use the python command followed by the
script's filename. The Python interpreter reads and executes the script from top to bottom.
1.2 Comments
Comments are just short descriptions along with the code.
piece of code.
The single-line comments in Python are denoted by the hash symbol “#” and
include no white spaces.
Multi-Line Comments in Python
Python does not have multi-line comments, but there are two ways we can
achieve this
#Welcome
#to
#Scaler
Advantages of Using Comments in
Python
Readability- Python comments greatly enhance the readability of the code.
Blocking out certain code- Blocking out code for execution is another avenue
def intro():
"""
This function prints Welcome to Scaler
Statement
print(‘i’)
multi-line statement
result = 2 + 3 * 5 - 5 + 6 - 3 + 4
print(result)
Indentation
what is a block?
• Constants: MAX_LIMIT, PI
Variables
A variable in Python is a reserved memory location to store
values.
Rules for naming a variable
Variable should either begin with an Uppercase(A to Z) or Lowercase(a
to z) character or an underscore(_).
Variable should always to use a meaningful name in Python. For
example – no_of_chocolates makes more sense than noc.
Which brings us to the next point. If a variable has multiple words, it is
advised to separate them with an underscore.
One should ensure that a variable name should not be similar to
keywords of the programming language.
One should also remember that even variable names are case-sensitive.
A variable should not begin with a digit or contain any white spaces or
special characters such as #,@,&.
Example of good variable names – my_name, my_dob.
Data Types: int, float, boolean, string and
Sequence data types
Numeric Data types
Integers
a = True
print("a =", a)
print("Data type of 'True':", type(a))
Sequence Data types
Strings:
print(name)
list
• Lists are mutable storage units that hold multiple data items
together.
• They can contain strings, numbers, other lists, tuples,
dictionaries, and more.
list_1 = ["Python", "Sequences"] # All string list
number = int("value")
Operators.
Operators are special symbols that carry arithmetic or logical
operations.
The value that the operator operates on is called the operand.
Arithmetic operators
Assignment operators
Comparison operators
logical operators
Identity operators
Membership operators
Boolean operators
Operator precedence
operators have different levels of precedence, which
determine the order in which they are evaluated.
When multiple operators are present in an expression, the
ones with higher precedence are evaluated first.
If the same precedence, their associativity comes into play,
determining the order of evaluation.
Operator precedence
Precedence Operators Description Associativity
Assignment expression
18 := Right to left
(walrus operator)
Ex:
a+b**c/d-(e-f)
a:·4
b:·1
c:·2
d:·4
e:·2
f:·3
a+(b**c)/d-(e-f): 5.25
Thank You……..