zoukankan      html  css  js  c++  java
  • Python语法

    import time;
    import turtle;

    # a = 23423432;b = 2342343452.23452;c = 234234323452.23452;d = 234293432.23452;
    # print(format(a,"10X"));
    # print(format(b,"<10.2f"));
    # print(format(c,"<10.2f"));
    # print(format(d,">10.2f"));
    #画一个三角形
    # turtle.pensize(3);
    # turtle.penup();
    # turtle.goto(-200,-50);
    # turtle.pendown();
    # turtle.circle(40, steps = 3);
    #画一个四边形
    # turtle.penup();
    # turtle.goto(-100,-50);
    # turtle.pendown();
    # turtle.circle(40,steps=4);
    #画一个五边形
    # turtle.penup();
    # turtle.goto(0,-50);
    # turtle.pendown();
    # turtle.circle(40,steps=5);
    #画一个圆
    # turtle.penup();
    # turtle.goto(100,-50);
    # turtle.pendown();
    # turtle.circle(40);
    #画一个红点
    # turtle.penup();
    # turtle.goto(200,-50);
    # turtle.pendown();
    # turtle.dot(6,"red");

    #画一个三角形
    # turtle.pensize(3);
    # turtle.penup();
    # turtle.goto(-200,-100);
    # turtle.pendown();
    # turtle.begin_fill();
    # turtle.color("yellow");
    # turtle.circle(40, steps = 3);
    # turtle.end_fill();
    #选择
    # number = eval(input("enter a number"));
    # if number % 5 == 0:
    # print("HIFive");
    # print("HIFive");
    # else:
    # print("HIFive");
    #循环
    # number = eval(input("enter a number"));
    # while number%5 != 0:
    # print("wrong number!");
    # number+=1;
    # initialValue = 0;
    # endValue = 9;
    # for i in range(initialValue,endValue):
    # print(i);
    #函数
    # def main(n,m):
    # print(function2(3.4));
    # def function2(n):
    # if n > 0:
    # return 1;
    # elif n == 0:
    # return 0;
    # elif n < 0:
    # return -1;
    # main(2,3);
    #类
    # class ClassName:
    # initializer;
    # methods();
    # import math;
    # class Circle:
    # def __init__(self,radius =1):
    # self.radius = radius;
    # def getPerimeter(self):
    # return 2 * self.radius*math.pi;
    # def getArea(self):
    # return self.radius * self.radius * math.pi;
    # def setRadious(self,radius):
    # self.radius = radius;
    # c = Circle(5);
    # print(c.radius);
    # print(c.getArea());
    # print(c.getPerimeter());
    #字符串函数
    #构造函数穿件字符串
    # s1 = str("i have spacestring");
    # s2 = str("Welcome");
    #用字符串值创建一个字符串
    # s3 = "";
    # s4 = "jin xueling";
    # print(len(s3));
    # print(len(s4));
    # print(max(s4));
    # print(min(s4));
    # for i in range(0,len(s4),2):
    # print(s4[i],end='');
    # print();
    # #python中的负下标
    # print(s4[-1]);
    # #截取
    # print(s4[1:4]);
    #连接和复制
    # print(s2+s4);
    # print(3*s4+"交换律"+s4*3);
    #包含
    # print("come" in s2);
    # print("come" not in s2);
    #比较字符串
    # print(s2 < s4);
    # for ch in s4:
    # print(ch);
    #字符串特征函数
    # print(s4.isalnum());
    # s4.isalnum();#atlast one number
    # s4.isalpha();#atlast one pharmeter
    # s4.isdigit();#all element is number
    # s4.isidentifier();#是否是Python标识符
    # s4.islower();#all element is lower;
    # s4.isupper();#all element is upper;
    # s4.isspace();#all element is space;
    #搜索字符串
    # str = " i am sOuce sTring "
    # str.endswith(s1);#判断str尾巴
    # str.startswith(s2);#判断str开头
    # str.find(s1);#查找str中s1最左边下标
    # str.rfind(s1);#查找str中是最右边下标
    # str.count(s1);#查找s1出现的次数,s1无覆盖
    #转换字符串
    # print(str.capitalize());
    # print(str.lower());
    # print(str.upper());
    # print(str.swapcase());
    # print(str.replace("g","替换"));
    #删除字符串中空格
    # print(str.lstrip());
    # print(str.rstrip());
    # print(str.strip());
    #校验回文串
    # def main():
    # s = input("enter a string").strip();
    # if isPalindrome(s):
    # print(s,"is a parlindrome");
    # else:
    # print(s,"is not a parlindrome");
    # def isPalindrome(s):
    # low = 0;
    # high = len(s)-1;
    # while low < high:
    # if s[low] != s[high]:
    # return False;
    # low+=1;
    # high-=1;
    # return True;
    # main();
    #列表:不同于字符串是字符的序列,列表是任何元素的序列
    # list1 = list("abcd");
    # list2 = list(range(3,5));
    # list3 = list[2,3,4];
    # items = "ni hao jin xue ling".split();
    # lst = [];
    # print("enter 10 numbers");
    # for i in range(10):
    # lst.append(eval(input()))
    #统计文件中的字符个数
    def main():
    filename ="E:workspace1pythonTestwordFile.txt";
    infile = open(filename,"r");
    counts = 26*[0];
    for line in infile:
    countLetters(line.lower(),counts);
    for i in range(len(counts)):
    if counts[i] != 0:
    print(chr(ord("a")+i)+" appears"+str(counts[i])+("time" if counts[i] == 1 else "times"));
    infile.close();
    def countLetters(line,counts):
    for ch in line:
    if ch.isalpha():
    counts[ord(ch) - ord('a')] += 1;
    main();
  • 相关阅读:
    关于 HTML5 的 11 个让人难以接受的事实
    【转】zookeeper 的监控工具
    arm+linux 裸机环境搭建之安装工具篇(eclipse)
    Unity 利用NGUI2.6.3做技能冷却的CD效果
    spring boot打包文件后,报错No such file or directory
    机器学习实战读书笔记(3)朴素贝叶斯
    机器学习实战读书笔记(2)决策树
    机器学习实战读书笔记(1)
    No operations allowed after connection closed--转
    简单理解Socket
  • 原文地址:https://www.cnblogs.com/jinb/p/8718409.html
Copyright © 2011-2022 走看看