SlideShare a Scribd company logo
Python



         -Mayur S. Mohite
Many languages require you to compile (translate) your program into a form that
the machine understands.

                         compile                    execute
       source code               byte code                 output
       Hello.java                Hello.class




Python is instead directly interpreted into machine instructions.
                         interpret
       source code               output
       Hello.py
Storing Values
Variable : A named piece of memory that can store a value.

Usage : Compute an expression's result, store that result into a variable
and use that variable later in the program.

Assignment statement : Stores a value into a variable.
Syntax :
                var_name = value

Examples :         x=5

A variable that has been given a value can be used in expressions.
Eg. x + 4 is 9
Printing Values

Print : Produces text output on the console.

Syntax :
          print "Message"
          print Expression
Prints the given text message or expression value on the console, and moves
the cursor down to the next line.

Examples :
       print "Hello, world!"
       age = 45
       print "You have", 65 - age, "years until retirement"

Output :
           Hello, world!
           You have 20 years until retirement
Input

input : Reads a number from user input.
raw_input : Reads a string of text from user input.

Example :
       age = input("How old are you? ")
       print "Your age is", age

         Output:
         How old are you? 53
         Your age is 53
       name = raw_input("Howdy, pardner. What's yer name?")
       print name, "... what a silly name!"
       Output:
       Howdy, pardner. What's yer name? Paris Hilton
       Paris Hilton ... what a silly name!
Loops

for loop : Repeats a set of statements over a group of values.

Example:
           for x in range(1, 6):
             print x, "squared is", x * x

if statement : Executes a group of statements only if a certain condition is true.
Otherwise, the statements are skipped.

Example:
           if gpa > 2.0:
              print "Your application is accepted."
if/else statement : Executes one block of statements if a certain
condition is True, and a second block of statements if it is False.

Example:
           if gpa > 2.0:
              print "Welcome to Mars University!"
           else:
              print "Your application is denied."

while loop : Executes a group of statements as long as a condition is True.
good for indefinite loops (repeat an unknown number of times)

Example:
           number = 1
           while number < 200:
             print number,
             number = number * 2
String

String : A sequence of text characters in a program.
Strings start and end with quotation mark " or apostrophe ' characters.
Examples:

"hello"
"This is a string"
"This, too, is a string. It can be very long!"

A string may not span across multiple lines or contain a " character.
"This is not
a legal String."
          "This is not a "legal" String either."
File Handling
Many programs handle data, which often comes from files.

Reading the entire contents of a file:
variableName = open("filename").read()

Example:
file_text = open("bankaccount.txt").read()

Reading a file line-by-line:

for line in open("filename").readlines():
  statements

Example:
count = 0
for line in open("bankaccount.txt").readlines():
  count = count + 1
print "The file contains", count, "lines."
Classes And Objects

A class acts like a container for all the methods and variable

A class definition looks like this:
class Point:
pass

Creating a new instance is called instantiation. To instantiate a
Point object, we call a function named Point:

blank = Point()

We can add new data to an instance using dot notation:
>>> blank.x = 3.0
>>> blank.y = 4.0

More Related Content

What's hot (8)

PPTX
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PDF
PHP7. Game Changer.
Haim Michael
 
PPTX
PHP Training Part1
than sare
 
PPT
07slide
Aboudi Sabbah
 
PDF
Strings IN C
yndaravind
 
PPTX
Php intro by sami kz
sami2244
 
PPTX
Lesson 4 constant
MLG College of Learning, Inc
 
ODP
PHP Web Programming
Muthuselvam RS
 
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PHP7. Game Changer.
Haim Michael
 
PHP Training Part1
than sare
 
07slide
Aboudi Sabbah
 
Strings IN C
yndaravind
 
Php intro by sami kz
sami2244
 
Lesson 4 constant
MLG College of Learning, Inc
 
PHP Web Programming
Muthuselvam RS
 

Viewers also liked (20)

PPT
Dot net guide for beginner
jayc8586
 
PPTX
C sharp
Ahmed Vic
 
PPT
C++ to java
Ajmal Ak
 
PPTX
Beginning Java for .NET developers
Andrei Rinea
 
PPT
Php i basic chapter 3
Muhamad Al Imran
 
PDF
A comparison between C# and Java
Ali MasudianPour
 
PPSX
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
PPTX
2.overview of c#
Raghu nath
 
PPT
Difference between C++ and Java
Ajmal Ak
 
PPT
Basics of c# by sabir
Sabir Ali
 
PPTX
C sharp
sanjay joshi
 
PPTX
C vs c++
ZTE Nepal
 
PPT
ASP.NET Session 1
Sisir Ghosh
 
PPTX
Java v/s .NET - Which is Better?
NIIT India
 
PPTX
Java script basic
Vithushan Vinayagamoorthy
 
PDF
Python overview
Hemant Kumar Tiwary
 
PPTX
C# basics
sagaroceanic11
 
PPTX
Java vs .net
Tech_MX
 
Dot net guide for beginner
jayc8586
 
C sharp
Ahmed Vic
 
C++ to java
Ajmal Ak
 
Beginning Java for .NET developers
Andrei Rinea
 
Php i basic chapter 3
Muhamad Al Imran
 
A comparison between C# and Java
Ali MasudianPour
 
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
2.overview of c#
Raghu nath
 
Difference between C++ and Java
Ajmal Ak
 
Basics of c# by sabir
Sabir Ali
 
C sharp
sanjay joshi
 
C vs c++
ZTE Nepal
 
ASP.NET Session 1
Sisir Ghosh
 
Java v/s .NET - Which is Better?
NIIT India
 
Java script basic
Vithushan Vinayagamoorthy
 
Python overview
Hemant Kumar Tiwary
 
C# basics
sagaroceanic11
 
Java vs .net
Tech_MX
 
Ad

Similar to Python basic (20)

PPTX
Python
MeHak Gulati
 
PPT
Help with Pyhon Programming Homework
Helpmeinhomework
 
ODP
An Intro to Python in 30 minutes
Sumit Raj
 
PPTX
Unit -1 CAP.pptx
malekaanjum1
 
PPTX
Python programing
hamzagame
 
PPTX
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa Thapa
 
PDF
python.pdf
BurugollaRavi1
 
PDF
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
PDF
python 34đź’­.pdf
AkashdeepBhattacharj1
 
PDF
python notes.pdf
RohitSindhu10
 
PPTX
made it easy: python quick reference for beginners
SumanMadan4
 
PPTX
Introduction to Python Programming
VijaySharma802
 
PDF
Cs4hs2008 track a-programming
Rashi Agarwal
 
PPTX
lecture 2.pptx
Anonymous9etQKwW
 
DOCX
A Introduction Book of python For Beginners.docx
kumarrabinderkumar77
 
PDF
Introduction to Python Programming | InsideAIML
VijaySharma802
 
PDF
Notes1
hccit
 
PPT
Python
Kumar Gaurav
 
ODP
Introduction to Python - Training for Kids
Aimee Maree Forsstrom
 
PDF
Tutorial on-python-programming
Chetan Giridhar
 
Python
MeHak Gulati
 
Help with Pyhon Programming Homework
Helpmeinhomework
 
An Intro to Python in 30 minutes
Sumit Raj
 
Unit -1 CAP.pptx
malekaanjum1
 
Python programing
hamzagame
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa Thapa
 
python.pdf
BurugollaRavi1
 
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python 34đź’­.pdf
AkashdeepBhattacharj1
 
python notes.pdf
RohitSindhu10
 
made it easy: python quick reference for beginners
SumanMadan4
 
Introduction to Python Programming
VijaySharma802
 
Cs4hs2008 track a-programming
Rashi Agarwal
 
lecture 2.pptx
Anonymous9etQKwW
 
A Introduction Book of python For Beginners.docx
kumarrabinderkumar77
 
Introduction to Python Programming | InsideAIML
VijaySharma802
 
Notes1
hccit
 
Python
Kumar Gaurav
 
Introduction to Python - Training for Kids
Aimee Maree Forsstrom
 
Tutorial on-python-programming
Chetan Giridhar
 
Ad

Recently uploaded (20)

PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PPTX
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PPTX
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PDF
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
PPTX
ENGLISH 8 REVISED K-12 CURRICULUM QUARTER 1 WEEK 1
LeomarrYsraelArzadon
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PPTX
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
PDF
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PDF
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
ENGLISH 8 REVISED K-12 CURRICULUM QUARTER 1 WEEK 1
LeomarrYsraelArzadon
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 

Python basic

  • 1. Python -Mayur S. Mohite
  • 2. Many languages require you to compile (translate) your program into a form that the machine understands. compile execute source code byte code output Hello.java Hello.class Python is instead directly interpreted into machine instructions. interpret source code output Hello.py
  • 3. Storing Values Variable : A named piece of memory that can store a value. Usage : Compute an expression's result, store that result into a variable and use that variable later in the program. Assignment statement : Stores a value into a variable. Syntax : var_name = value Examples : x=5 A variable that has been given a value can be used in expressions. Eg. x + 4 is 9
  • 4. Printing Values Print : Produces text output on the console. Syntax : print "Message" print Expression Prints the given text message or expression value on the console, and moves the cursor down to the next line. Examples : print "Hello, world!" age = 45 print "You have", 65 - age, "years until retirement" Output : Hello, world! You have 20 years until retirement
  • 5. Input input : Reads a number from user input. raw_input : Reads a string of text from user input. Example : age = input("How old are you? ") print "Your age is", age Output: How old are you? 53 Your age is 53 name = raw_input("Howdy, pardner. What's yer name?") print name, "... what a silly name!" Output: Howdy, pardner. What's yer name? Paris Hilton Paris Hilton ... what a silly name!
  • 6. Loops for loop : Repeats a set of statements over a group of values. Example: for x in range(1, 6): print x, "squared is", x * x if statement : Executes a group of statements only if a certain condition is true. Otherwise, the statements are skipped. Example: if gpa > 2.0: print "Your application is accepted."
  • 7. if/else statement : Executes one block of statements if a certain condition is True, and a second block of statements if it is False. Example: if gpa > 2.0: print "Welcome to Mars University!" else: print "Your application is denied." while loop : Executes a group of statements as long as a condition is True. good for indefinite loops (repeat an unknown number of times) Example: number = 1 while number < 200: print number, number = number * 2
  • 8. String String : A sequence of text characters in a program. Strings start and end with quotation mark " or apostrophe ' characters. Examples: "hello" "This is a string" "This, too, is a string. It can be very long!" A string may not span across multiple lines or contain a " character. "This is not a legal String." "This is not a "legal" String either."
  • 9. File Handling Many programs handle data, which often comes from files. Reading the entire contents of a file: variableName = open("filename").read() Example: file_text = open("bankaccount.txt").read() Reading a file line-by-line: for line in open("filename").readlines(): statements Example: count = 0 for line in open("bankaccount.txt").readlines(): count = count + 1 print "The file contains", count, "lines."
  • 10. Classes And Objects A class acts like a container for all the methods and variable A class definition looks like this: class Point: pass Creating a new instance is called instantiation. To instantiate a Point object, we call a function named Point: blank = Point() We can add new data to an instance using dot notation: >>> blank.x = 3.0 >>> blank.y = 4.0