SlideShare a Scribd company logo
INTRODUCTION TO PYTHON
Raj Hakani
Gujarat Technological Univeristy
PRINT FUNCTION
str1 = ‘Python code’
str2 = ‘Matlab code’
print(str1)
print(str2)
Output: Python code
Matlab code
print(str1, end=’ ‘)
print(str2)
Output: Python code Matlab code
print(str1, end=’, ‘)
print(str2)
Output: Python code, Matlab code
PRINT FUNCTION
items = [ 1, 2, 3, 4, 5]
for item in items:
print(item)
Output:
1
2
3
4
5
items = [ 1, 2, 3, 4, 5]
for item in items:
print(item, end=’ ‘)
Output:
1 2 3 4 5
OPERATORS
Addition + Subtraction -
Multiplication * Exponentiation **
Division / Integer division / /
Remainder %
Binary left shift << Binary right shift >>
And & Or |
Less than < Greater than >
Less than or equal to <= Greater than or equal to >=
Check equality == Check not equal !=
PRECEDENCE OF OPERATORS
Parenthesized expression ( ….. )
Exponentiation **
Positive, negative, bitwise not +n, -n, ~n
Multiplication, float division, int division, remainder *, /, //, %
Addition, subtraction +, -
Bitwise left, right shifts <<, >>
Bitwise and &
Bitwise or |
Membership and equality tests in, not in, is, is
not, <, <=, >, >=, !=, ==
Boolean (logical) not not x
Boolean and and
Boolean or or
Conditional expression if ….. else
PRECEDENCE OF OPERATORS
Examples:
a = 20
b = 10
c = 15
d = 5
e = 2
f = (a + b) * c / d
print( f)
g = a + (b * c) / d - e
print(g)
h = a + b*c**e
print(h)
MULTIPLE ASSIGNMENT
Python allows you to assign a single value to several variables
simultaneously.
a = b = c = 1.5
a, b, c = 1, 2, " Red“
Here, two integer objects with values 1 and 2 are assigned to
variables a and b respectively and one string object with the
value "Red" is assigned to the variable c.
SPECIAL USE OF + AND *
Examples:
x = "Python is "
y = "awesome."
z = x + y
print(z)
Output:
Python is awesome.
print(‘It is’ + 2*’very ’ + ’hot.’)
Output:
It is very very hot.
USE OF ”, N, T
Specifying a backslash () in front of the quote character in a string
“escapes” it and causes Python to suppress its usual special meaning. It is
then interpreted simply as a literal single quote character:
>>> print(" ”Beauty of Flower” ")
”Beauty of Flower”
>>> print('Red n Blue n Green ')
Red
Blue
Green
>>> print("a t b t c t d")
a b c d
CREATING OUTPUT FILE
file = open(‘output.txt’, ‘a+’)
items = [‘mango’, ‘orange’, ‘banana’, ‘apple’]
for item in items:
print(item, file = file)
file.close()
# Write a python program to open and read a file
a=open(“one.txt”, ”r”)
content = a.read()
print(content)
a.close( )
# Write a python program to open and write “hello world” into a file.
f=open("file.txt","a")
f.write("hello world")
f.close( )
# Python program to write the content “Hi python programming” for the existing file.
f=open("MyFile.txt",'w')
f.write("Hi python programming")
f.close()
# Write a python program to open and write the content to file and read it.
f=open("abc.txt","w+")
f.write("Python Programming")
print(f.read())
f.close()
Thank You

More Related Content

PPT
901131 examples
DOCX
Mcq cpup
PPTX
Python programming workshop session 3
PDF
Astronomical data analysis by python.pdf
PPTX
GE8151 Problem Solving and Python Programming
PPTX
Chapter1 python introduction syntax general
PDF
Introduction to python programming
901131 examples
Mcq cpup
Python programming workshop session 3
Astronomical data analysis by python.pdf
GE8151 Problem Solving and Python Programming
Chapter1 python introduction syntax general
Introduction to python programming

Similar to PythonPPT_Raj Programming for 1st year .pptx (20)

PPTX
Class 12 computer. 1 Python intro-1.pptx
PDF
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
DOCX
Basic python laboratoty_ PSPP Manual .docx
PPTX
Strings in python are surrounded by eith
PPTX
Basics of Python and Numpy jfhfkfff.pptx
PDF
Chapter 2 Decision Making (Python Programming Lecture)
PDF
The Ring programming language version 1.8 book - Part 94 of 202
PPTX
MODULE. .pptx
PDF
Data Handling.pdf
PPTX
Data Handling
PPTX
funadamentals of python programming language (right from scratch)
PPT
Matlab1
PPT
Beginning with C++.ppt thus us beginnunv w
PPTX
Python knowledge ,......................
PDF
datastructure-1 lab manual journals practical
PPTX
Python programming workshop
PPS
basics of C and c++ by eteaching
PDF
Functional Concepts for OOP Developers
PPT
Python High Level Functions_Ch 11.ppt
PPTX
Keep it Stupidly Simple Introduce Python
Class 12 computer. 1 Python intro-1.pptx
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
Basic python laboratoty_ PSPP Manual .docx
Strings in python are surrounded by eith
Basics of Python and Numpy jfhfkfff.pptx
Chapter 2 Decision Making (Python Programming Lecture)
The Ring programming language version 1.8 book - Part 94 of 202
MODULE. .pptx
Data Handling.pdf
Data Handling
funadamentals of python programming language (right from scratch)
Matlab1
Beginning with C++.ppt thus us beginnunv w
Python knowledge ,......................
datastructure-1 lab manual journals practical
Python programming workshop
basics of C and c++ by eteaching
Functional Concepts for OOP Developers
Python High Level Functions_Ch 11.ppt
Keep it Stupidly Simple Introduce Python
Ad

More from ArpitaPatel527902 (7)

PPT
ch8Bkdeedch aporbobotlity of the machine l
PPT
Classifier_1ch8 machine learning and deep
PPT
Exper_Machine Learning Data analysis data.ppt.ppt
PPT
Exper_Machine Learning Experimental data.ppt
PPTX
Unit 1 Fundamenatal of AI_1 for 1st year .pptx
PPTX
Design Engineeing project presentation for
PPTX
object detetion with voice description.pptx
ch8Bkdeedch aporbobotlity of the machine l
Classifier_1ch8 machine learning and deep
Exper_Machine Learning Data analysis data.ppt.ppt
Exper_Machine Learning Experimental data.ppt
Unit 1 Fundamenatal of AI_1 for 1st year .pptx
Design Engineeing project presentation for
object detetion with voice description.pptx
Ad

Recently uploaded (20)

PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Trump Administration's workforce development strategy
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
20th Century Theater, Methods, History.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
IGGE1 Understanding the Self1234567891011
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Weekly quiz Compilation Jan -July 25.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Trump Administration's workforce development strategy
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Computer Architecture Input Output Memory.pptx
B.Sc. DS Unit 2 Software Engineering.pptx
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
20th Century Theater, Methods, History.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
IGGE1 Understanding the Self1234567891011
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx

PythonPPT_Raj Programming for 1st year .pptx

  • 1. INTRODUCTION TO PYTHON Raj Hakani Gujarat Technological Univeristy
  • 2. PRINT FUNCTION str1 = ‘Python code’ str2 = ‘Matlab code’ print(str1) print(str2) Output: Python code Matlab code print(str1, end=’ ‘) print(str2) Output: Python code Matlab code print(str1, end=’, ‘) print(str2) Output: Python code, Matlab code
  • 3. PRINT FUNCTION items = [ 1, 2, 3, 4, 5] for item in items: print(item) Output: 1 2 3 4 5 items = [ 1, 2, 3, 4, 5] for item in items: print(item, end=’ ‘) Output: 1 2 3 4 5
  • 4. OPERATORS Addition + Subtraction - Multiplication * Exponentiation ** Division / Integer division / / Remainder % Binary left shift << Binary right shift >> And & Or | Less than < Greater than > Less than or equal to <= Greater than or equal to >= Check equality == Check not equal !=
  • 5. PRECEDENCE OF OPERATORS Parenthesized expression ( ….. ) Exponentiation ** Positive, negative, bitwise not +n, -n, ~n Multiplication, float division, int division, remainder *, /, //, % Addition, subtraction +, - Bitwise left, right shifts <<, >> Bitwise and & Bitwise or | Membership and equality tests in, not in, is, is not, <, <=, >, >=, !=, == Boolean (logical) not not x Boolean and and Boolean or or Conditional expression if ….. else
  • 6. PRECEDENCE OF OPERATORS Examples: a = 20 b = 10 c = 15 d = 5 e = 2 f = (a + b) * c / d print( f) g = a + (b * c) / d - e print(g) h = a + b*c**e print(h)
  • 7. MULTIPLE ASSIGNMENT Python allows you to assign a single value to several variables simultaneously. a = b = c = 1.5 a, b, c = 1, 2, " Red“ Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively and one string object with the value "Red" is assigned to the variable c.
  • 8. SPECIAL USE OF + AND * Examples: x = "Python is " y = "awesome." z = x + y print(z) Output: Python is awesome. print(‘It is’ + 2*’very ’ + ’hot.’) Output: It is very very hot.
  • 9. USE OF ”, N, T Specifying a backslash () in front of the quote character in a string “escapes” it and causes Python to suppress its usual special meaning. It is then interpreted simply as a literal single quote character: >>> print(" ”Beauty of Flower” ") ”Beauty of Flower” >>> print('Red n Blue n Green ') Red Blue Green >>> print("a t b t c t d") a b c d
  • 10. CREATING OUTPUT FILE file = open(‘output.txt’, ‘a+’) items = [‘mango’, ‘orange’, ‘banana’, ‘apple’] for item in items: print(item, file = file) file.close()
  • 11. # Write a python program to open and read a file a=open(“one.txt”, ”r”) content = a.read() print(content) a.close( ) # Write a python program to open and write “hello world” into a file. f=open("file.txt","a") f.write("hello world") f.close( )
  • 12. # Python program to write the content “Hi python programming” for the existing file. f=open("MyFile.txt",'w') f.write("Hi python programming") f.close() # Write a python program to open and write the content to file and read it. f=open("abc.txt","w+") f.write("Python Programming") print(f.read()) f.close()