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
  • 相关阅读:
    UIAutomator环境搭建
    Appium环境搭建
    Java单元测试 Junit TestNG之介绍
    IDEA操作jdbc总结
    tomcat启动失败的解决办法
    Java 图书管理项目
    某某服-EDR终端任意用户登录 0day
    深X服 EDR终端检测系统RCE漏洞复现
    通达OA任意文件上传+文件包含RCE漏洞复现(附自写EXP)
    Joomla-3.4.6远程代码执行漏洞复现
  • 原文地址:https://www.cnblogs.com/liulipeng/p/2794135.html
Copyright © 2011-2022 走看看