Your SlideShare is downloading. ×
0
Python basic
Python basic
Python basic
Python basic
Python basic
Python basic
Python basic
Python basic
Python basic
Python basic
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Python basic

118

Published on

Just an Introduction about python. …

Just an Introduction about python.
For details about language go to,
http://www.diveintopython.net/toc/index.html

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
118
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Python -Mayur S. Mohite
  • 2. Many languages require you to compile (translate) your program into a form thatthe machine understands. compile execute source code byte code output Hello.java Hello.classPython is instead directly interpreted into machine instructions. interpret source code output Hello.py
  • 3. Storing ValuesVariable : A named piece of memory that can store a value.Usage : Compute an expressions result, store that result into a variableand use that variable later in the program.Assignment statement : Stores a value into a variable.Syntax : var_name = valueExamples : x=5A variable that has been given a value can be used in expressions.Eg. x + 4 is 9
  • 4. Printing ValuesPrint : Produces text output on the console.Syntax : print "Message" print ExpressionPrints the given text message or expression value on the console, and movesthe 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. Inputinput : 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. Whats yer name?") print name, "... what a silly name!" Output: Howdy, pardner. Whats yer name? Paris Hilton Paris Hilton ... what a silly name!
  • 6. Loopsfor loop : Repeats a set of statements over a group of values.Example: for x in range(1, 6): print x, "squared is", x * xif 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 certaincondition 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. StringString : 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 nota legal String." "This is not a "legal" String either."
  • 9. File HandlingMany 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(): statementsExample:count = 0for line in open("bankaccount.txt").readlines(): count = count + 1print "The file contains", count, "lines."
  • 10. Classes And ObjectsA class acts like a container for all the methods and variableA class definition looks like this:class Point:passCreating a new instance is called instantiation. To instantiate aPoint 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

×