SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque (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
 

Semelhante 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
 

Semelhante 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

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Último (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

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