SlideShare a Scribd company logo
7
Most read
10
Most read
14
Most read
BASICS ON PYTHON
PROGRAMMING
PROF. POOJA B S
 About the Course
 Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python is
simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program
maintenance. Python supports modules and packages, which encourages program modularity and code reuse
 Course Objectives
 Learn Syntax and Semantics and create Functions in Python.
 Handle Strings and Files in Python.
 Understand Lists, Dictionaries and Regular expressions in Python.
 Implement Object Oriented Programming concepts in Python
 Introduction to Network Programming in Python
 Course Outcomes
 Explain basic principles of Python programming language
 Interpret the fundamentals of Python and usage of various support libraries
 Problem Solving and Programming Capability
 To learn how to design and program Python applications
Introduction to Python: Basics of Python, Variables,
Expressions, Statements
 Guido Van Rossum in 1991
 Open Source
 General purpose programming language.
 Applications:
 GUI Applications
 Website Applications
 Mobile Applications
 Artificial Intelligence
 Machine Learning Algorithms
Where Python is Used?
 Google
 Netflix
 Dropbox
 National Security Agency (USA)
 BitTorrent
 NASA
Python Development Environments
 PyDev on Eclipse
 Notepad++
 Komodo IDE
 PC (PyCharm)
 Bluefish
 Vim
 LiClipse
 IDLE (Integrated Development and Learning Environment)
How can I download Python?
 The python can be downloaded from the link given below:
https://www.python.org/downloads/
Basics of Python Programming
 >>> Chevron
 Comments in Python:
 #
 ‘’’……………..’’’ or “””……………”””
 Interactive Mode and Scripting Mode
 Keyboard Interrupt:
 Ctrl+c
 Quit the program:
 quit()
 Interpreter v/s Compiler
 Types of Errors in a Program:
 Syntax Errors
 Logical Errors
 Semantic Errors
Simple Programs
1. print(“Hello! Welcome to Python World”) # Hello! Welcome to Python World
2. print(Hello) #Error
3. print(‘Hello’) # Hello
4. print(‘’‘Hello’’’) # Hello
5. X=10 #30
Y=20
print(x+y)
6. num1 = 1.5 #The sum of 1.5 and 6.3 is 7.8
num2 = 6.3
sum = num1 + num2
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Variables
 Variable is a named literal to store a value.
 Need not be declared before usage in python
 Use “=” to assign value
 Rules for naming a variable:
 Variable name should not be a keyword
 Should not start with a number or special character
 Can only contain special characters “_”
 Eg:
1. 3a=5 #invalid
2. A$=10 #valid
3. if=15 #invalid
Values and Types
 The type of a value can be checked using “type” function
 Eg:
1. type(‘Hello’)
2. type(3)
3. type(100.4)
4. type(2/3)
5. type(325%6)
6. type(2==3)
7. type(‘500’)
8. type(“500”)
9. x=10
y=‘Hi’
print(x)
print(y)
type(x)
type(y)
Operators and Operands
 Arithmetic Operators:
 Relational or Comparison Operators:
+ Addition [a+b]
- Subtraction [a-b]
* Multiplication [a*b]
/ Quotient [a/b] eg: 5/3=1.66667
% Remainder [a%b] eg: 5%3=2
// Floor Division [a//b] eg: 5//3=1
** Exponent [a**b] is equal to a^b eg: 2**3=2^3=8
< Less Than [a<b]
> Greater Than [a>b]
== Comparison [a==b]
 Bitwise Operators
 Assignment Operators
 Used to assign values to variables
 Compound Assignment Operator is: =+
 Eg: x=3
y=5
x+=y #Same as x=x+y
print(x) #8
& AND
| OR
~ NOT
^ XOR
>> Right Shift
<< Left Shift
 Assign different types to variables in a single statement
 Eg:
x, y, str = 3, 4.2, “Hello”
print(“x=”,x, “y=”,y,”str=”,str) #x=3 y=4.2 str=Hello
 Expressions
Combination of values, variables and operators is known as an expression.
Eg: x=5
y=x+10
z=x+y-3
Order of Operations
 Evaluation of Expressions follows on PEMDAS rule
P Parenthesis ()
E Exponent **
M Multiplication *
D Division / and %
A Addition +
S Subtraction -
Eg: print(2**3) #8
print(2**3**2) #512
print(5*2/4) #2.5
print(5/4*2) #2.5
 String Operations
 Use + operator for string concatenation
 Eg: x=“32”
y=“40”
print(x+y) #3240
 User Input
 Built in function: input()
 Eg: 1] str1= input()
print(“Entered String is:”, str1) #Entered String is Hello Python!
2] x= input(“Enter a number”)
type(x) #<class 'str'>
3] x= int(input(“Enter a number”))
type(x) #<class ‘int'>

More Related Content

PPTX
Fundamentals of Python Programming
PPTX
Python in 30 minutes!
PPTX
Python - An Introduction
PPTX
Basic Python Programming: Part 01 and Part 02
PPTX
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
PPTX
Intro to Python Programming Language
PDF
Operators in python
PPT
Introduction to python
Fundamentals of Python Programming
Python in 30 minutes!
Python - An Introduction
Basic Python Programming: Part 01 and Part 02
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Intro to Python Programming Language
Operators in python
Introduction to python

What's hot (20)

PDF
Python basic
PPTX
Python
PPT
Python ppt
PDF
Data Structures Practical File
PPTX
Python Basics
PPTX
Python
PPTX
Python Tutorial Part 1
PDF
Operators in python
PPTX
Python programming
PPTX
Python | What is Python | History of Python | Python Tutorial
PDF
Intro to Python for Non-Programmers
PDF
Python-01| Fundamentals
PPT
Functions in C++
PPTX
Looping statements in C
PDF
Python final ppt
PDF
03 function overloading
PPTX
Operators and expressions in C++
PDF
Python Decision Making
PDF
Introduction to python programming
PPT
Python Programming ppt
Python basic
Python
Python ppt
Data Structures Practical File
Python Basics
Python
Python Tutorial Part 1
Operators in python
Python programming
Python | What is Python | History of Python | Python Tutorial
Intro to Python for Non-Programmers
Python-01| Fundamentals
Functions in C++
Looping statements in C
Python final ppt
03 function overloading
Operators and expressions in C++
Python Decision Making
Introduction to python programming
Python Programming ppt
Ad

Similar to Python Basics (20)

PDF
Python basic programing language for automation
DOCX
A Introduction Book of python For Beginners.docx
PDF
Python Programming by Dr. C. Sreedhar.pdf
PPTX
lecture 2.pptx
PPT
Python programming
PPTX
Introduction To Python.pptx
PPTX
Lecture 1 .
PPTX
Introduction to python programming ( part-1)
PPTX
python_module_.................................................................
PPTX
Module-1.pptx
PPTX
Welcome to python workshop
PPT
Spsl iv unit final
PPT
Spsl iv unit final
PDF
python notes.pdf
PDF
pythonQuick.pdf
PDF
python 34💭.pdf
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
PPTX
modul-python-all.pptx
PPTX
Learn about Python power point presentation
PPTX
Introduction to Python and Basic Syntax.pptx
Python basic programing language for automation
A Introduction Book of python For Beginners.docx
Python Programming by Dr. C. Sreedhar.pdf
lecture 2.pptx
Python programming
Introduction To Python.pptx
Lecture 1 .
Introduction to python programming ( part-1)
python_module_.................................................................
Module-1.pptx
Welcome to python workshop
Spsl iv unit final
Spsl iv unit final
python notes.pdf
pythonQuick.pdf
python 34💭.pdf
Basic concept of Python.pptx includes design tool, identifier, variables.
modul-python-all.pptx
Learn about Python power point presentation
Introduction to Python and Basic Syntax.pptx
Ad

More from Pooja B S (6)

PPTX
Iteration
PPTX
String Methods and Files
PPTX
Lists in Python
PPTX
Dictionary
PPTX
String Manipulation in Python
PPTX
Python Conditionals and Functions
Iteration
String Methods and Files
Lists in Python
Dictionary
String Manipulation in Python
Python Conditionals and Functions

Recently uploaded (20)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Institutional Correction lecture only . . .
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
01-Introduction-to-Information-Management.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
master seminar digital applications in india
PPTX
Lesson notes of climatology university.
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPH.pptx obstetrics and gynecology in nursing
Institutional Correction lecture only . . .
Sports Quiz easy sports quiz sports quiz
Anesthesia in Laparoscopic Surgery in India
01-Introduction-to-Information-Management.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
master seminar digital applications in india
Lesson notes of climatology university.
GDM (1) (1).pptx small presentation for students
Final Presentation General Medicine 03-08-2024.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Insiders guide to clinical Medicine.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Basic Mud Logging Guide for educational purpose
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

Python Basics

  • 2.  About the Course  Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python is simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse  Course Objectives  Learn Syntax and Semantics and create Functions in Python.  Handle Strings and Files in Python.  Understand Lists, Dictionaries and Regular expressions in Python.  Implement Object Oriented Programming concepts in Python  Introduction to Network Programming in Python  Course Outcomes  Explain basic principles of Python programming language  Interpret the fundamentals of Python and usage of various support libraries  Problem Solving and Programming Capability  To learn how to design and program Python applications
  • 3. Introduction to Python: Basics of Python, Variables, Expressions, Statements  Guido Van Rossum in 1991  Open Source  General purpose programming language.  Applications:  GUI Applications  Website Applications  Mobile Applications  Artificial Intelligence  Machine Learning Algorithms
  • 4. Where Python is Used?  Google  Netflix  Dropbox  National Security Agency (USA)  BitTorrent  NASA Python Development Environments  PyDev on Eclipse  Notepad++  Komodo IDE  PC (PyCharm)  Bluefish  Vim  LiClipse  IDLE (Integrated Development and Learning Environment)
  • 5. How can I download Python?  The python can be downloaded from the link given below: https://www.python.org/downloads/
  • 6. Basics of Python Programming  >>> Chevron  Comments in Python:  #  ‘’’……………..’’’ or “””……………”””  Interactive Mode and Scripting Mode  Keyboard Interrupt:  Ctrl+c  Quit the program:  quit()  Interpreter v/s Compiler  Types of Errors in a Program:  Syntax Errors  Logical Errors  Semantic Errors
  • 7. Simple Programs 1. print(“Hello! Welcome to Python World”) # Hello! Welcome to Python World 2. print(Hello) #Error 3. print(‘Hello’) # Hello 4. print(‘’‘Hello’’’) # Hello 5. X=10 #30 Y=20 print(x+y) 6. num1 = 1.5 #The sum of 1.5 and 6.3 is 7.8 num2 = 6.3 sum = num1 + num2 print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
  • 8. Variables  Variable is a named literal to store a value.  Need not be declared before usage in python  Use “=” to assign value  Rules for naming a variable:  Variable name should not be a keyword  Should not start with a number or special character  Can only contain special characters “_”  Eg: 1. 3a=5 #invalid 2. A$=10 #valid 3. if=15 #invalid
  • 9. Values and Types  The type of a value can be checked using “type” function  Eg: 1. type(‘Hello’) 2. type(3) 3. type(100.4) 4. type(2/3) 5. type(325%6) 6. type(2==3) 7. type(‘500’) 8. type(“500”) 9. x=10 y=‘Hi’ print(x) print(y) type(x) type(y)
  • 10. Operators and Operands  Arithmetic Operators:  Relational or Comparison Operators: + Addition [a+b] - Subtraction [a-b] * Multiplication [a*b] / Quotient [a/b] eg: 5/3=1.66667 % Remainder [a%b] eg: 5%3=2 // Floor Division [a//b] eg: 5//3=1 ** Exponent [a**b] is equal to a^b eg: 2**3=2^3=8 < Less Than [a<b] > Greater Than [a>b] == Comparison [a==b]
  • 11.  Bitwise Operators  Assignment Operators  Used to assign values to variables  Compound Assignment Operator is: =+  Eg: x=3 y=5 x+=y #Same as x=x+y print(x) #8 & AND | OR ~ NOT ^ XOR >> Right Shift << Left Shift
  • 12.  Assign different types to variables in a single statement  Eg: x, y, str = 3, 4.2, “Hello” print(“x=”,x, “y=”,y,”str=”,str) #x=3 y=4.2 str=Hello  Expressions Combination of values, variables and operators is known as an expression. Eg: x=5 y=x+10 z=x+y-3
  • 13. Order of Operations  Evaluation of Expressions follows on PEMDAS rule P Parenthesis () E Exponent ** M Multiplication * D Division / and % A Addition + S Subtraction - Eg: print(2**3) #8 print(2**3**2) #512 print(5*2/4) #2.5 print(5/4*2) #2.5
  • 14.  String Operations  Use + operator for string concatenation  Eg: x=“32” y=“40” print(x+y) #3240  User Input  Built in function: input()  Eg: 1] str1= input() print(“Entered String is:”, str1) #Entered String is Hello Python! 2] x= input(“Enter a number”) type(x) #<class 'str'> 3] x= int(input(“Enter a number”)) type(x) #<class ‘int'>