python简单基础介绍

python简单基础介绍

1.开发环境的搭建

我用的开发环境是pycharm,下载地址:www.jetbrains.com

2.Python变量的定义

a = 10
b = 10

c = a + b

print c

3.Python判断语句的使用

\#coding=utf-8
score = 0

if score >= 60:
    print ("及格")
elif score >= 40:
    print ("不好")
else:
    print ("太差了")

需要注意编码方式的指定。

4.python循环的简单使用

for i in range(0,100):
    print (i)
    print ("item {0}".format(i))
    print ("item {0} {1}".format(i,"hello python"))

注意字符串的拼接,占位符的使用。

5.python函数的定义

def sayhello():
    print ("hello world")

def max(a,b):
    if a>b:
        return a
    else:
        return b

sayhello()
print (max(2,3))

这里定义了两个函数,调用了两个函数

6.python类的定义,对象的使用

class Person:
    def __init__(self,name):
        self._name = name
    def run(self):
        print ("{0}我正在跑步!".format(self._name))

class Student(Person):
    def __init__(self,name):
        Person.__init__(self,name)
    def study(self):
        print ("我正在学习!")

person = Person("张三")
person.run()

student = Student("王武")

student.study()

7,python文件的导入(对外部文件的引用)

这里需要先创建两个python文件.

mylib.py

class Dog:
    def cry(self):
        print ("wang wang wang !")

loadlib.py

from  mylib import Dog

dog = Dog()
dog.cry()

运行loadlib.py,即可使用外部文件的类

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值