Python入门小练习
Posted Aurora-RenShuoyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python入门小练习相关的知识,希望对你有一定的参考价值。
#输出,输入,类,构造方法
import math s = \'Hello world!\' print(\'你好,Aurora!!!\') print(math.log2(8)) print(\'helao\'[3]) print(len("12316465159651")) print(type(3.14)) print(type(True)) print(s[6]) use_age = int(input(\'请输入年龄\\n\')) print("你的年龄是"+str(use_age)+"岁") a = int(input("输入\\n")) if a == 1: print("ooo") elif a==2: print("aaa") elif a== 9: print("adasd") else: print("asdsad4") class Student: def __init__(self,name ,id): self.name = name self.id = id; self.grade = "语文":0,"数学":0 def set_grade(self,crouse,grade): if crouse in self.grade: self.grade[crouse]=grade; chen = Student("小陈","10086") print(chen.name) chen.set_grade("数学",95) print(chen.grade)
#读写文件
with open("./poem.txt","w",encoding="utf-8")as f: f.write("123\\n456\\n789")
以上是关于Python入门小练习的主要内容,如果未能解决你的问题,请参考以下文章