编辑默认模板:

        Seting—file and code templates—编辑

变量:

  变量有不同的类型,分为整型int、浮点型flout、字符串型str、复数型complax。

  Python里不需要预先定义变量的类型,根据赋值类型决定,但可以强制定义变量的类型,例如:

  int(变量名),str(变量名)等等。

打印输出:

  print(变量,“hello world”)

  打印多个变量,中间以逗号隔开,打印文字需要使用引号包住,打印变量不需要。

  打印变量类型,print(type(变量名))

  打印多行,先用一个变量=‘‘‘将需要打印的文字’’’,print(该变量)

输入:

  input(‘输入的提示语’),定义输入变量类型使用int(input(‘输入提示语’)),其他类型类似。

注释:

  注释单行,在需要注释的代码前加#,注释多行''''''或者“““”””

字符串拼接:

  方法一:

  info = '''
  - - - - information of %s- - - - -
  dream: %s
  name: %s
  job: %s
  age:%d
  '''%(第一个%代表的变量,第二个,first_name,job,age)
View Code
 方法二:
  info2 = '''
  - - - - information of {_name}- - - - -
  dream: {_dream}
  name: {_first_name}
  job: {_job}
  age:{_age}
  '''.format(_name=name,
           _first_name=first_name,
           _job=job,
           _age=age,
           _dream=dream)
View Code
    备注:需要在变量后,加.format(给临时变量赋值),引用临时变量加大括号{}
 方法三:
info3= '''
  - - - - information of {0}- - - - -
  dream: {1}
  name: {2}
  job: {3}
  age:{4}
  '''.format(name,dream,first_name,job,age)
View Code
    备注:拼接时先用0,1,2,3,4代替,然后.format(变量名,变量名)变量名需要按顺序排列
 方法四:
 info4= '''
  - - - - information of '''+name+'''- - - - -
  dream: '''+dream+'''
  name: '''+first_name+'''
  job: '''+job+'''
  age:'''+str(age)+'''
  '''
View Code
    备注:直接用'''+变量名+'''拼接,只能拼接字符串
判断语句格式:
 if 判断条件:
   运行结果#(可加多行,但是必须缩进)
 elif#相当于else if
   运行结果#(可加多行,但是必须缩进)
 else:
   运行结果#(可加多行,但是必须缩进)
View Code
while循环:
  while 循环进行条件:
    循环体,需要i+=1,否则不会自动给i加1,需要缩进
  else:
    循环结束后运行
View Code
for循环:
  for i in range(初值,终止值,步长):#for i in Iterable:
    循环体
  else:
    循环结束后运行
View Code
break与contune:
  break指终止当前循环,contune终止本次循环自动使用下一个i值循环。