zoukankan      html  css  js  c++  java
  • Python参考手册第一章: Python简介(一)

    一、Python简介
    1.1 print "Hello World"
    1.2 变量和算术表达式
    #print
    principal = 1000
    rate = 0.05
    numyears = 5
    year = 1
    
    while year <= numyears:
        principal = principal * (1 + rate)
    
        print year, principal 
    #    print(year, principal)
    
        print "%3d %0.2f" % (year, principal)
    #    print("%3d %0.2f" % (year, principal))
    
        print format(year,"3d"), format(principal, "0.2f")
    #    print(format(year,"3d"), format(principal,"0.2f"))
    
        print "{0:3d} {1:0.2f}".format(year,principal)
    #    print("{0:3d} {1:0.2f}".format(year,principal))
    
        year += 1

    #同一行上用分号隔开多条语句
    #循环主体由缩进表示,每个缩进层次使用4个空格
    #格式化字符序列
    #%3d将一个整数格式化为在一个宽度为3的列中右对齐
    1.3条件语句 a = 1 b = 2 if a < b: print "Computer says yes" else: print "Computer syas no" if a < b: pass # Do nothing else: print "Computer syas no" # or and not product = "game" type1 = "pirate memory" age = 9 if product == "game" and type1 == "pirate memory" \ and not (age < 4 or age > 8): print "I will take it!" else: print "no...." #switch case suffix = ".html" if suffix == ".html": content = "text/html" elif suffix == ".jpg": content = "image/jpeg" elif suffix == ".png": content = "image/png" else: raise RuntimeError("Unknown content type") print content #True False s = 'p' if 'spam' in s: has_spam = True else: has_spam = False print has_spam has_spam = "spam" in s print has_spam
  • 相关阅读:
    第一篇:数据仓库概述
    第五篇:数据库系统的实现
    第四篇:SQL
    Django框架ORM常用参数汇总_模型层
    Django框架ORM常用字段汇总_模型层
    Boost.Asio的使用技巧
    Boost库之asio io_service以及run、run_one、poll、poll_one区别
    Boost::asio io_service 实现分析
    boost asio中io_service类的几种使用
    boost::io_service解读
  • 原文地址:https://www.cnblogs.com/liulipeng/p/2794135.html
Copyright © 2011-2022 走看看