Home Introduction To Python Notes
Post
Cancel

Introduction To Python Notes

pycharm 一些常用的快捷键

  • command + 1 回到项目菜单栏
  • ctrl + shift + R 运行当前脚本
  • command + shift + F12 全屏编辑
  • Option + Space 打开快速定义查询

Jupyter Notebook 一些常用快捷键

  • esc退出单元格选择
  • J 或者 K 跳到上一个或者下一个代码块中
  • M 代码块转换为 markdown 格式
  • Y 代码块转换成代码格式
  • DD 删除单元格
  • A 或者 B 在当前代码块上面或者下面新增代码块

Python 基础(复习用)

Introduction

  • About
  • Navigating Around
  • Course View
  • Editor
  • Task Description
  • Our first program
  • Comments

Variables

  • Variable definition
  • Undefined variable
  • Variable types
  • Type conversion
  • Arithmetic operators
  • Assignments
  • Boolean operators
  • Comparison operators

Strings

  • Concatenation
  • String multiplication
  • String indexing
  • String negative indexing
  • String slicing
  • In operator
  • String length
  • Character escaping
  • Basic string methods
  • String formatting
  • F-strings

Data structures

  • List introduction
  • Lists operations
  • List items
  • Nested Lists
  • Tuples
  • Join methods
  • Dictionaries
  • Dictionary keys() and values()
  • In keyword

Condition expressions

  • Boolean operators
  • Boolean operators order
  • If statement
  • Else and elif parts in if statement

Loop

  • For loop
  • Loop over a string
  • Nested for Loop
  • List Comprehension
  • Nested List Comprehension
  • While loop
  • Break keyword
  • Else with loops ⚠️
    • Python also allows loop statements to have an else clause. It is executed when the loop terminates through exhaustion of the iterable (with for) or when the condition becomes False (with while), but not when the loop is terminated by a break statement.
  • Continue keyword

Functions

  • Definition
  • Parameters and call arguments
  • Return value

    • Functions may return a value to the caller, using the keyword return . You can use the returned value to assign it to a variable or just print it out. In fact, even functions without a return statement do return a value. This value is called None (it’s a built-in name). Writing the value None is normally suppressed by the interpreter, but if you really want to see it, you can use print(some_func()).
  • Default parameters
    • It is also possible to define functions with a variable number of arguments. There are three forms, which can be combined. The most useful form is to specify a default value for one or more arguments. This creates a function that can be called with fewer arguments than it is defined with. For example, check out the first function in the code editor. This function can be called in several ways:

      • giving only the mandatory argument a: multiply_by(3)

      • giving one of the optional arguments: multiply_by(3, 47), or multiply_by(3, c=47)

      • or even giving all arguments: multiply_by(3, 47, 0)

  • Keyword Arguments
  • Args and kwargs ⚠️
  • Recursion
    • example: factorial (阶乘) 函数

Class and objects

  • Definition
  • Variable access
  • Update variable
  • The self parameters
  • Special__init__methods
  • __str__vs__repr__
    • 针对字符串类型的转换,repr() 方法是在外层加引号,这一特性在 eval() 操作时特别有用
    • 控制台输出时默认调用 repr()print() 输出调用 str
  • Class and Instance Variables

Modules and packages

  • Import module
  • Build-in modules
  • Form import
  • Packages
  • Executing modules as scripts ⚠️
    • 需要注意脚本函数的执行顺序,会先执行引用包内的所有脚本
    • 如果需要控制执行,用if __name__ == "__main__": 进行判断

File input output

  • Open file
  • Read file
  • Write file
  • What next
This post is licensed under CC BY 4.0 by the author.

Steve Jobs: The lost interview

区块链数据解析 资料收集

Comments powered by Disqus.