python基础语法

		python基础语法小汇总
test.py
# coding utf-8
#1. 打印常量
print("1. 打印常量") 
print("hello python") 


#2. 定义变量
print("2. 定义变量") 
a = 10
b = 20
c=a+b
print("c = {0}".format(c))


#3. 条件判断
print("3. 条件判断") 
score = 65


if score>=80 :
    print("good")
elif score>=60 :
    print("及格")
    print ("马马虎虎")
elif score>=40 :
    print("not good")
else :
    print("bad")
    
#4. 循环
print("4. 条件判断")    
for i in range(0,5):
    print(i)
    


#5. 定义函数
print("5. 定义函数")     
def hello():
    print("hello wlh")
hello()


#6.面向对象
print("6. 面向对象 class")     
class test :
    def hi() :
        print("print from test hi()")
        hello()
        
test.hi()


#7.引入python文件
print("7.引入python文件")   
import other


class1 = other.otherclass()
class1.display()

other.py


#另一个文件
class otherclass:
    def display(self):
        print("open the other file")

#otherclass.display()

输出结果:

1. 打印常量
hello python
2. 定义变量
c = 30
3. 条件判断
及格
马马虎虎
4. 条件判断
0
1
2
3
4
5. 定义函数
hello wlh
6. 面向对象 class
print from test hi()
hello wlh
7.引入python文件
open the other file



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值