coursera_intro_to_python_notebook_1

http://www.codeskulptor.org/#user10_RPMkJnEXC4v3qe8.py

this is my first mini python project


1 function&&more operations

function starts with key word "def",such as an example
 
def compute_area(base,height):
  area= ( 1 /2 ) * base * height;
  return area
 
 
the end of the header is a colon,means the following lines indented belongs to the function,no matther how many lines, but with the same amount
 
so,the block indented with a same amount belongs to the function
 
in last case , it has 2 lines(with the same amount indented).
when you stop the indentation , the block of code is done
 
Call the function 
a1 = compute_area(3,8)
print a1
#print 12
 
 
def print_hello():
     print "hello world"
 
Call the function
print_hello()          
#OK
a=print_hello()
print a;
#will print "None"
 
if you forget or you dont need a return statement,it automatically add one
 
 
 
__________________________________________________________________________________________
 
more operations 
 
a="0"
b="1"
print a,b,":00"
#show "0 1 :00"
 
+operator
combine the strings
print a+b+":00"
#show "01:00"
 
function str: convert something to string
such as
hour=3
print str(hour)
 
 
import module:
 
such as
improt math
improt simplegui
 
print math.pi
 
improt random

原文地址:https://www.cnblogs.com/yangtianxing/p/3042033.html