学习python-day02

1.循环语句

  1. 循环打印“人生苦短,我用python”

    while True:    
        print('人生苦短,我用Python。')
    
  2. while后加入条件

    while 1>0 and 2>1:    
    	print('人生苦短,我用Python。')
    
  3. 数字相加

    """ 
    count = 1 
    value = count + 1 
    print(value) 
    """ 
    """ 
    count = 1 
    count = count + 1 
    print(count) 
    """
    
  4. 请通过循环,让count每次循环+1

    count = 1 
    while True:    
    print(count)    
    count = count + 1
    
  5. 请通过循环,1 2 3 .. 10.

count = 1 
while count <= 10:    
    print(count)    
    count = count + 1
 print('结束')

  1. break, break是终止当前循环 .

  2. continue,本次循环如果遇到continue,则不在继续往下走,而是回到while条件位置。

  3. while else

  4. 其他

    • 快速注释ctrl+?
    • pycharm 断点1565624055772

2.字符串格式化

  • %s

    #字符串格式化存在的意义
    name = input('姓名:')
    do = input('在干什么:')
    template = "s%在教室,s%."%(name,do,)  #do后面的,要追加保留
    print(template)
    
    
    #直接做占位符 
    # template = "我是%s,年龄%s, 职业%s。" %("alex",73,'讲鸡汤',) 
    # print(template)
    
  • %d---整数格式化

    # template = "我是%s,年龄%d, 职业%s。" %("alex",73,'讲鸡汤',) 
    # print(template)
    
  • %%---输出中遇到真正意义的%

    # name = 'alex' 
    # template = "%s现在手机的电量是100%%" %(name,) 
    # print(template
    
  • 练习

    name = input('请输入姓名:') 
    age = input('请输入年龄:') 
    job = input('请输入职业:') 
    hobby = input('请输入爱好:') 
    msg = ''' ------------ info of Alex Li ---------
    Name  : %s 
    Age   : %s 
    job   : %s 
    Hobbie: %s 
    ------------- end ----------------'''
    data = msg %(name,age,job,hobby,) print(data)
    

3.运算符

  • 算术运算

    # 练习题: 1 ~ 100 之间所有的数相加。 
    	total = 0
        count = 1 
        while count <=100: 
            total = total + count 
            count = count + 1
        print(total)
    
    # 练习题:打印 1 ~ 100 之间的奇数。 
    count = 1
    total
    while <= 100:
        count += 1
        if count % 2 ==1:
            print(count)
    
  • 赋值运算

  • 逻辑运算

    • 优先级 在没有()的情况下not 优先级高于 and,and优先级高于or,即优先级关系为( )>not>and>or,同一优先级从左往右计算。
  • 数据类型转换

posted @ 2019-08-13 00:18  自动化交易  阅读(128)  评论(0)    收藏  举报