Some basic concepts about Python:
- Function: Sth. that helps u directly or indirectly achieve some target
- DataType: Distinguish elements for different uses
- Grammar: Standards for coding
- Structure: Logic for coding
- Packages: Sth. that provide useful fuxs for u to manipulate
Before coding(Notice & some Grammar):
1. Encoding for Chinese:
#-*- coding:utf-8 -*-
Other Choices: GB2312、GBK、GB18030
2.Path
Ex. for linux
$ PATH=$PATH:/usr/local/python3/bin/python3
3.Keywords
Python has some keywords that cannot be edited or changed
Ex: False,True,None,and,or,class,if,def,...,etc.
For search:
import keyword
keyword.kwlist
4.Indent 缩进 & Multi-line code
Indent:
Python use indent (TAB) to display code blocks (no use for {})
if True:
print ("True")
else:
print ("False")
Multi-line code:
Use " \ " to connect
total = item_one + \
item_two + \
item_three
5. Print & Import
Print in Python 3.0:
a="x"
print(a) #output with "Enter" 换行
print (a,end=" ") #output with " " 不换行
Import:
将整个模块(somemodule)导入
从某个模块中导入某个函数
从某个模块中导入多个函数
将某个模块中的全部函数导入
分别对应:
import somemodule
from somemodule import somefunction
from somemodule import firstfunc, secondfunc, thirdfunc
from somemodule import *
网友评论