美文网首页
2018-09-19

2018-09-19

作者: shytian | 来源:发表于2018-09-19 17:44 被阅读0次

    1,安装Python

    https://www.python.org下载python安装包,点击执行安装

    2,使用IDLE

    1)打开IDLE,选择“File”-“New File”新建一个文件
    2)输入如下代码

    print('Hello,python!')
    

    3)选择“File”-“Save”,输入文件名“hello”保存文件
    4)选择“Run”-“Run Module”运行文件,查看输出结果如下

    Hello,python!
    

    3,变量

    1)命名

    字母、数字、下划线

    2)赋值

    =,input

    name='wangzixi'
    name=input('What's your name?  ')
    

    4,数字

    整数int: 0,1,10,99999,-1,-50
    浮点数float:3.14,0.05,-23.4567

    5,运算符号

    加:+
    减:-
    乘:*
    除:/
    括号:()

    6,字符串str

    'wangzixi',"wangziyi","What's your name?"

    7,列表 []

    family=['dad','mom','xixi','yiyi']

    8,for循环

    for x in range(10):
      print(x)
    
    total=0
    for i in range(1,101):
      total=total+i
    print(total)
    
    family=['dad','mom','xixi','yiyi']
    for person in family:
      print(person)
    

    9,注释

    #这是单行注释
    print('Hello')  #print('Hello, single line comment')
    /*
    这是多行注释
    我是新的一行
    print('Hello, multiple lines comment')
    */
    

    10,布尔bool

    真:True
    假:False

    x=5
    x>4
    x>6
    

    11,逻辑运算

    与(而且、并且):and
    或(或者):or
    非(取反):not

    x=5
    x>4 and x >3
    x>4 and x> 6
    x>4 or x>3
    x>4 or x>6
    
    x>6
    not x>6
    

    12,比较

    大于:>
    小于:<
    等于:==
    大于等于:>=
    小于等于:<=
    不等于:!=

    x=5
    x>4
    x>=5
    x<3
    x<=10
    x==6
    x!=7
    
    s1='hello'
    s2=='world'
    s='hello'
    s1==s2
    s1==s
    

    13,while循环

    i=1
    total=0
    while i<=100:
      total=total+i
      i=i+1
    print(total)
    

    14,条件判断

    if

    age=eval(input('How old are you? '))
    if age>=6:  #如果
      print('You can go to school.')
    

    if ...else...

    age=eval(input('How old are you? '))
    if age>=6:  #如果
      print('You can go to school.')
    else: #那么、否则
      print('You can't go to school.')
    

    if...elif...else

    age=eval(input('How old are you? '))
    if age>=6:  #如果
      print('You can go to school.')
    elif age>=3: #否则如果
      print('You can go to youeryuan.')
    else:#否则
      print('You can't go to any school.')
    

    相关文章

      网友评论

          本文标题:2018-09-19

          本文链接:https://www.haomeiwen.com/subject/aeminftx.html