Step-by-step Learn python (3) Basic supplement

Source: Internet
Author: User

Recently learning Python in the system is based on a set of Python3 courses Mooc above. This paper mainly summarizes the key points of the basic part.

    • 1.python Basic data types
    • 2.python operator
    • 3. Build a simple and efficient IDE environment
    • 4. Packages, modules, classes, functions, variables
1.python Basic data types

# -*- coding: utf-8 -*-  #空对象的类型验证print('空对象的类型验证:')print(type(0))print(type(''))print(type([]))print(type(()))print(type(set()))print(type({}))#所有空的对象都是Falseprint('所有空的对象都是False:')print(bool(0))print(bool(''))print(bool([]))print(bool(()))print(bool(set()))print(bool({}))#与之对应,所有非空的对象都是Trueprint('与之对应,所有非空的对象都是True:')print(bool(-7))print(bool('Alfred'))print(bool([1, 2, 3]))print(bool((4, 5)))print(bool({1, 3, 7}))print(bool({1:'a', 2:'b', 3:'c'}))
2.python operator

Exercises:

a = 1b = c = 2x = (not a or b + 2 == c)print(x)

Full precedence is described in parentheses:

(not a) or ((b + 2) == c)最终代码运行结果为:False。
3. Build a simple and efficient IDE environment

I am using the Mac platform Sublime Text + Python 3.7 + package Control + Sublimecodeintel for the time being.
For Python3 Environment Building (Tools--build system--New build system), refer to Python3.sublime-build:

{    "cmd": ["/usr/local/bin/python3", "-u", "$file"],    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",    "selector": "source.python"}

The following statement can print out hello with "command + B", confirming that Python3 can use:

print('Hello',end='')#编译运行结果:Hello[Finished in 0.1s]
4. Packages, modules, classes, functions, variables

The package corresponds to a folder, the package of bread containing __init__.py this file, itself is a module, sub-package can be and module-lateral;
module corresponding to the file, the module should write the most should be the class;
Classes contain functions and variables, and functions and variables can be understood as some of the characteristics of the class itself.

Class (Object-oriented three major features): encapsulation, inheritance, polymorphism.
This part has a lot of object-oriented knowledge is completely universal, for object-oriented language is a similar way of thinking.

A full understanding of object-oriented and deep learning of functions are the key directions for follow-up.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: