python 入门

应用IDLE(python gui)作为编辑器
#1 你好,世界:

>>> print("hello, world")
hello, world
>>>


#2 编写py文件
应用快捷键:
Ctrl+ N 新开一个GUI窗口:
把刚才的代码save到hello.py文件中,按F5 运行一下:
>>> ================================ RESTART ================================
>>>
hello, world
>>>


#3 写个for循环吧:

word=['a','b','c','d','e','f','g']
for x in word:
print(x)

打印结果:

a
b
c
d
e
f
g


#4 写个函数吧:

def sum(a,b):
return a+b
ss=sum
result = ss(2,3)
print(result)


#5 定义一个class吧:

#类和继承
class Base:
def __init__(self):
self.data=[]
def add(self,x):
self.data.append(x)
def addtwice(self,x):
self.add(x)
self.add(x)
#child class extends Base

class Child(Base):
def plus(self,a,b):
return a+b
oChild = Child()
oChild.add("str1")
print(oChild.data)
print(oChild.plus(2,3))

运行结果:

['str1']
5


想要说明的几点:
1.python代码对缩进的要求是很严格的,缩进不对,代码就校验不通过,报语法错误
2.reference website:http://www.cnblogs.com/fortran/archive/2010/08/22/1805690.html
3.有一本电子书:深入python3 可供参考
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值