当前位置:   article > 正文

Python常用API及其效果实现------Python_python apl

python apl
  1. a = 100;
  2. b = 500;
  3. if a > b:
  4. print("A大一些");
  5. else:
  6. print("B大一些");
  7. import random;
  8. print(random.randint(1, 100));
  9. class Cat:
  10. @staticmethod
  11. def eat():
  12. print("猫吃鱼")
  13. def sleep(self):
  14. print("猫睡觉")
  15. cat = Cat()
  16. Cat.eat()
  17. cat.eat()
  18. cat.sleep()
  19. list = ["哈哈", "哈哈哈", "哈哈哈哈", 1, True]
  20. # for 变量 in 可以迭代的对象:
  21. # pass
  22. range(1, 10)
  23. str = 'hello'
  24. # java 数组: 列表、元祖
  25. for i in str:
  26. print(i)
  27. def sum_2_num(num1, num2):
  28. result = num1 + num2
  29. print("%d + %d = %d" % (num1, num2, result))
  30. sum_2_num(30, 40)
  31. class Person:
  32. def __init__(self, name, age):
  33. self.name = name
  34. self.age = age
  35. print("孩子被生出来了")
  36. def __del__(self):
  37. print("人死了")
  38. def __str__(self):
  39. print("人的生平介绍")
  40. p = Person('zhangsan', 19)
  41. print(p.age)
  42. print(p.name)
  43. p.__str__()
  44. class Student(Person, Cat):
  45. def __init__(self):
  46. print("学生出生了");
  47. # stu = Student();
  48. # stu.__str__();
  49. # stu.eat();
  50. # stu.sleep();
  51. try:
  52. int('abc')
  53. except:
  54. print("有异常")
'
运行
a = 100;
b = 500;
if a > b:
    print("A大一些");
else:
    print("B大一些");
import random;

print(random.randint(1, 100));


class Cat:
    @staticmethod
    def eat():
        print("猫吃鱼")

    def sleep(self):
        print("猫睡觉")


cat = Cat()
Cat.eat()
cat.eat()
cat.sleep()
list = ["哈哈", "哈哈哈", "哈哈哈哈", 1, True]

# for 变量 in 可以迭代的对象:
#     pass
range(1, 10)
str = 'hello'
# java  数组:  列表、元祖

for i in str:
    print(i)


def sum_2_num(num1, num2):
    result = num1 + num2

    print("%d + %d = %d" % (num1, num2, result))


sum_2_num(30, 40)


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
        print("孩子被生出来了")

    def __del__(self):
        print("人死了")

    def __str__(self):
        print("人的生平介绍")


p = Person('zhangsan', 19)
print(p.age)
print(p.name)
p.__str__()


class Student(Person, Cat):
    def __init__(self):
        print("学生出生了");


# stu = Student();
# stu.__str__();
# stu.eat();
# stu.sleep();


try:
    int('abc')
except:
    print("有异常")
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号