Vu Python - 备考宝典

此篇博客注重概念的总结,以及它们的英文表述。

来吧,对着PPT抠定义,走起!

Topic 2 – Operators and Variables

1.What is an expression?
An expression is made of operands (values) and operators.
表达式由操作数(值)和运算符组成。
1
2.Order of Precedence(优先级)

3.What is a variable?
A variable is a memory location in computer memory. It has a type and a name. This memory location can store different values of the same type.(变量是计算机内存中的一个内存位置。它有一个类型和一个名称。此内存位置可以存储同一类型的不同值。)

习题讲解:
Variables例题精讲

Selection and Repetition Structures

好像没啥概念,刷下例题吧。
Selection and Repetition Structures例题精讲

Strings and Text files

别急,概念集中在class类那个章节里。先看看例题吧。
Strings and Text files例题精讲

Lists and Dictionaries

1.The values in lists are called elements or sometimes items.

2.一个列表也可以是列表中的元素
如:[‘John’, 2.0, 5, [10, 20]] is also a list

3.The index starts at 0.
索引从0开始

4.Tuples(与 list 的区别是元组不可修改)

  • Unlike lists, tuples are immutable.
  • Structure of a tuple can not be changed
  • Tuples are used when there is a need of an unchanging list.
  • 定义元组时如果只有一个元素则需要加英文逗号。这样是为了避免和增加优先级的那个小括号混交。例:

错误写法:

list = (1)
print(list)

运行结果:

1

正确写法:

list = (1,)
print(list)

运行结果:

(1,)
  • A list can be converted to a tuple
list = [7,"whh"]
print(tuple(list))

运行结果:

(7, 'whh')

5.Dictionaries
格式: {key : value , key : value ……}
eg:

list = {7:"whh","whh":7 }
print(list)

运行结果:

{7: 'whh', 'whh': 7}

注意:

  • In dictionaries, keys can be of any data type.
  • Keys are unique in each dictionary
  • Keys must be of an immutable data type such as strings, numbers, or tuples.
list = {7:"whh","whh":7 }
print(list)
print(list.keys())
print(list.values())
list["whh"] = "whh" # 修改字典中的值
print(list)

运行结果:

{7: 'whh', 'whh': 7}
dict_keys([7, 'whh'])
dict_values(['whh', 7])
{7: 'whh', 'whh': 'whh'}

具体题目解析请点击下方链接

Lists and Dictionaries例题精讲

Design with Functions

1.Why use functions?

  • Functions avoid repetitive code
  • Function modular code
  • Helps division of labor

2.Top down design
Top down design is breaking a large problem into several small problems.
And then solving each small problem in order to solve the initial large problem.(说白了就是自定义函数将问题拆分)

3.Recursive Functions
A recursive function is a function that calls itself.

4.variable

  • Local variable(局部变量)
    A local variable can only be used inside the function it is declared.
  • Global variable(全局变量)
    A global variable is declared in the body of the program and can be used by any function in the program.
  • Instance variable(实例变量)
    Instances variables must begin with self.

Turtle Graphics

海龟画图这节没啥定义,看看实例吧。
海龟画图实例

Graphical User Interface

1.widgets
GUI programs use objects called widgets.
Examples of widgets are: Label,Entry Field,Button,Radio button, etc.

2.Benefits of using GUI

  • The user is not constrained to enter inputs in a particular order.
  • Running different data sets does not require re-entering all of the data.
  • The user cannot enter an unrecognized command.

3.What is Tk?
Tk is a free and open-source, cross-platform widget toolkit.
It provides a library of basic elements of GUI widgets

4.What is Tkinter?
Tkinter is a set of wrappers that implement the Tk widgets as Python classes.

5.mainloop()
mainloop() function start an infinite event-loop that processes user events by calling an endless loop of the window.

Graphical User Interface例题精讲

Design with Classes

1.Class
A Class is a user defined datatype which contains properties and methods in it.

2.object
Objects are the real ‘things’ that is generated using the class definition.

A class is a blueprint of an object. An object is an instance belonging to a class.

3.def __ init __

  • def __ init __ is the constructor of the class.
  • init must begin and end with two underscores.
  • The purpose of the constructor is to initialize an individual object’s attributes.

4.__ str __
__ str __ method builds and return a string representation of an object’s state.

5.Accessor Method(“get” Method)
An accessor method is used to return the value of an instance variable. These methods are also called ‘get’ methods. They simply allow the user to observe the state of an object but not to change.

6.Mutator Method(“set” Method)
A mutator method is used to set a value of an instance variable. These methods are also called ‘set’ methods. They allow the user to modify the state of an object.

Design with Classes例题精讲

Object Oriented Programming Concepts(OOP)

  • Encapsulation(封装)
  • Abstraction(抽象)
  • Inheritance(继承)
  • Polymorphism(多态)

1.Encapsulation
This means that the internal representation of an object can not be seen from outside of the objects definition.
To read values of the created object ‘get’ and __ str __ methods were used.

2.Abstraction
Abstraction and Encapsulation are closely related.
Abstraction is achieved by encapsulation.
简单说就是因为封装了,所以看不见,所以抽象。

3.Inheritance
eg:
在test1.py文件中写父类

class Employee(object):
    def __init__(self,empname,empnum,empposition):
        self._empname = empname
        self._empnum = empnum
        self._empposition = empposition

    def getname(self):
        return self._empname

    def getnum(self):
        return self._empnum

    def getpostion(self):
        return self._empposition

换个py文件写子类:

from test1 import Employee

class permEmployee(Employee):
    def __init__(self,empname,empnum,empposition,salary):
        # 通过继承,将父类的变量传给子类
        Employee.__init__(self,empname,empnum,empposition)
        self._salary = salary

    def getsalary(self):
        return self._salary

    def calcBonus(self):
        bonus = (self._salary * 0.1) + 500
        return bonus

    def __str__(self):
        # 子类继承父类中的方法,注意self不可省略
        return Employee.getname(self) + "Bonus : $ " + str(self.calcBonus())


pe = permEmployee("whh","777","Analyst",85000)
print(pe)

运行结果:

whhBonus : $ 9000.0

Benefits of using inheritance?

  • it is possible to re-use code and reduce duplicate code.
  • Saves time in programming due to reusability of code.
  • Subclasses becomes more manageable which helps extending individual subclasses

4.Polymorphism

Different subclass objects call the same parent method to produce different execution results.

Benefits of using Polymorphism?
Polymorphism can increase the flexibility of code

eg:
父类class类:

class Animal(object):
    def __init__(self,name,mood):
        self._name = name
        self._mood = mood

    def getname(self):
        return self._name

    def getmood(self):
        return  self._mood

    def speak(self):
        print("Heard a " + self._mood + " " + self._name)

子类:

from test1 import Animal

class Goat(Animal):
    def __init__(self,name,mood):
        Animal.__init__(self,name,mood)

    def speak(self):
        Animal.speak(self) # 调用父类speak方法


class Monkey(Animal):
    def __init__(self, name, mood):
        Animal.__init__(self, name, mood)

    def speak(self):
        Animal.speak(self) # 调用父类speak方法

ans1 = Goat("Goat","happy")
ans2 = Monkey("Monkey","unhappy")
ans1.speak()
print()
ans2.speak()

运行结果:

Heard a happy Goat

Heard a unhappy Monkey

解析:
可见,同样是调用父类的speak方法,但是他们的输出却不一样,这便是多态。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
deja_vu3d - cesium是一款功能强大的地球可视化框架。它基于Cesium.js开发,提供了丰富的功能集,可用于创建令人惊叹的三维地球模型。 deja_vu3d - cesium的主要功能包括: 1. 三维地球可视化:deja_vu3d - cesium允许用户展示全球范围内的地理数据,包括地形、海洋、建筑物等。它提供了高度精确的地球模型,可以实时旋转和缩放,让用户以全新的视角探索地球表面。 2. 实时数据可视化:该框架支持对实时数据的可视化,可以将传感器数据、气象数据等实时更新的数据集成到地球模型中。用户可以通过动态的图表、标签和交互式元素来直观地理解数据趋势和模式。 3. 矢量和栅格数据显示:deja_vu3d - cesium支持导入和展示各种矢量和栅格数据。用户可以将自己的地理信息数据集成到地球模型中,进行可视化和空间分析。 4. 相机和视角控制:框架提供了强大的相机和视角控制功能,用户可以自由调整视角、俯瞰地球表面、漫游各个地区。这使得用户能够更好地理解地理空间关系和模式,并更好地展示和交流地理数据。 5. 动画和时间轴:deja_vu3d - cesium允许用户创建动画效果,通过时间轴控制地球模型的演变。这对于展示历史数据、模拟气候变化等具有重要意义。 总而言之,deja_vu3d - cesium是一款功能强大的地球可视化框架,它提供了丰富的功能集,帮助用户创建令人惊叹的三维地球模型,并可可视化和分析各种地理数据。无论是用于科研、教育还是商业应用,deja_vu3d - cesium都能为用户提供出色的地球可视化体验。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值