Python3 基础语法,从入门到精通一

哈哈 阅读:682 2021-03-31 21:21:10 评论:0
print('Hello World Python'); 
 
#python 变量定义 
x = 1; 
y = 2; 
z = x + y; 
print(z); 
 
#if 判断语句 
score = 50; 
if score >= 90: 
    print("优秀"); 
elif score >= 80: 
    print("良好"); 
elif score >= 60: 
    print("及格"); 
else: 
    print("不及格"); 
 
#for 循环 
for i in range(0,10): 
    print(i); 
    print("Index {0},{1}".format(i,"blogs")) 
print("for is end"); 
 
#python 函数定义 
def Say(): 
    print("Hello Python3"); 
 
def Size(x,y): 
    if x > y: 
        return x; 
    else: 
        return y; 
 
Say(); 
print("size is {0}".format(Size(1,2))); 
 
#Python3 定义Class 
class Person: 
    def __init__(self,name): 
        self.name = name; 
    def getName(self): 
        print("my name is {0}".format(self.name)); 
 
person = Person("zzg"); 
person.getName(); 
 
#Python3 继承 
class Man(Person): 
    def __init__(self,name,age): 
        Person.__init__(self,name); 
        self.age = age; 
    def getAge(self): 
        print("my age is {0}".format(self.age)); 
 
man = Man("zzg","26"); 
man.getName(); 
man.getAge(); 
 
 
 
 
 
 
 

标签:Python
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号