Python学习之路

Python 十分钟入门  http://www.runoob.com/w3cnote/python-ten-minute-introductory-tutorial.html

Python 菜鸟教程  http://www.runoob.com/python/python-tutorial.html

PyCharm安装Numpy  https://jingyan.baidu.com/article/3aed632ed414d5701080912e.html

python 文件读取

   with open(xml_path, "r") as fr:
        content = fr.read()

python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence"

解决办法1.

    with open(xml_path, "r", encoding="UTF-8") as fr:
        content = fr.read()

解决办法2.

    with open(xml_path, "rb") as fr:
        content = fr.read()

Python 操作符

1. and 比 or 有更高的优先级

2. x^y 在 python中为 x**y

Python类class中方法的self问题,

self代表类的实例,而非类

类的方法与普通的函数只有一个特别的区别——它们必须有一个额外的第一个参数名称, 按照惯例它的名称是 self。

#!/usr/bin/python
# -*- coding: UTF-8 -*-

class Employee:
    '所有员工的基类'
    empCount = 0

    def __init__(self, name, salary):
        self.name = name
        self.salary = salary
        Employee.empCount += 1

    def displayCount(self):
        print("Total Employee %d" % Employee.empCount)

    def displayEmployee(self):
        print("Name : ", self.name, ", Salary: ", self.salary)

t = Employee("sff", "1000")
t.displayEmployee()

Python缩进问题:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值