Python学习笔记(一),,注释:两类 # 或


注释:两类 # 或 """ """ 或 ‘‘‘ ‘‘‘

#coding=utf-8 (中文)

--------------------------------------------------
变量:无需先声明,赋值时声明和定义
比如:
data_i = 1
str = ‘hello‘ #字符串可用‘‘或""
list = [1,2,[1,2],‘1321‘]

列表:相当于C语言的数组的扩展。其元素可以是普通的数据类型也可以是列表或是其他的数据类型
list = [1,2,[1,2],‘1321‘]
常用的函数有: append() remove()
--------------------------------------------------
语句和语句块
每一个语句后没有“;”,比如:print("-----------")
用缩进来表示语句块,而不是常见的大括号{}
比如(语句块):
cave_numbers = list(range(0,20))
unvisited_caves = list(range(0,20))
visited_caves = []
visit_cave(0)
--------------------------------------------------
if语句
if condition:
body
else:
body

while语句
while condition:
body

for语句
for i in listName:
body

import用法
from random import choice
import random
--------------------------------------------------
函数
def functionname(Parameter1Name, Parameter2Name,...):
function body
return something or not
例如:
def setup_caves(cave_numbers):
""" Creat the starting list of caves """
caves = []
for i in cave_numbers:
caves.append([])
return caves
--------------------------------------------------
输入和输出
print(1, end=‘/t‘) (or in ‘‘ you can put everything)
input(‘>‘) (or in ‘ ‘ you can put everything)

遇到的函数:
randoms = list(range(20)) #0-19的一个列表
random_i = choice(random) #在列表中随机的选择一个元素

Python学习笔记(一),布布扣,bubuko.com

Python学习笔记(一)

评论关闭