您的位置:首页 > 编程语言 > Python开发

coursera_intro_to_python_notebook_1

2013-04-25 11:24 525 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐