SlideShare una empresa de Scribd logo
1 de 10
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (8)

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
 
PHP Training Part1
PHP Training Part1PHP Training Part1
PHP Training Part1
 
07slide
07slide07slide
07slide
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
 
Lesson 4 constant
Lesson 4  constantLesson 4  constant
Lesson 4 constant
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 

Destacado (20)

3rd june
3rd june3rd june
3rd june
 
Dot net guide for beginner
Dot net guide for beginner Dot net guide for beginner
Dot net guide for beginner
 
C sharp
C sharpC sharp
C sharp
 
C++ to java
C++ to javaC++ to java
C++ to java
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
 
java vs C#
java vs C#java vs C#
java vs C#
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
 
Difference between C++ and Java
Difference between C++ and JavaDifference between C++ and Java
Difference between C++ and Java
 
Basics of c# by sabir
Basics of c# by sabirBasics of c# by sabir
Basics of c# by sabir
 
C sharp
C sharpC sharp
C sharp
 
C vs c++
C vs c++C vs c++
C vs c++
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1
 
Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?
 
Java script basic
Java script basicJava script basic
Java script basic
 
Python overview
Python   overviewPython   overview
Python overview
 
C# basics
C# basicsC# basics
C# basics
 
Java vs .net
Java vs .netJava vs .net
Java vs .net
 

Similar a Python basic

Python programing
Python programingPython programing
Python programinghamzagame
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelpmeinhomework
 
Lecture 0 - CS50's Introduction to Programming with Python.pdf
Lecture 0 - CS50's Introduction to Programming with Python.pdfLecture 0 - CS50's Introduction to Programming with Python.pdf
Lecture 0 - CS50's Introduction to Programming with Python.pdfSrinivasPonugupaty1
 
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
2016 bioinformatics i_python_part_2_strings_wim_vancriekingeProf. Wim Van Criekinge
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to ProgrammingCindy Royal
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekingeProf. Wim Van Criekinge
 
Python introduction 2
Python introduction 2Python introduction 2
Python introduction 2Ahmad Hussein
 

Similar a Python basic (20)

Python
PythonPython
Python
 
Python programing
Python programingPython programing
Python programing
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 
Lecture 0 - CS50's Introduction to Programming with Python.pdf
Lecture 0 - CS50's Introduction to Programming with Python.pdfLecture 0 - CS50's Introduction to Programming with Python.pdf
Lecture 0 - CS50's Introduction to Programming with Python.pdf
 
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
PHP Reviewer
PHP ReviewerPHP Reviewer
PHP Reviewer
 
Java Basics 1.pptx
Java Basics 1.pptxJava Basics 1.pptx
Java Basics 1.pptx
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Python Basics
Python Basics Python Basics
Python Basics
 
C Language Lecture 16
C Language Lecture 16C Language Lecture 16
C Language Lecture 16
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
 
Python basic
Python basicPython basic
Python basic
 
Python introduction 2
Python introduction 2Python introduction 2
Python introduction 2
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 

Último

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Último (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

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