zoukankan      html  css  js  c++  java
  • python学习笔记之基础数据和控制

    注释:

    单行注释 #

    多行注释'''    '''

    注意:当注释中有汉字时需要在python文件的第一行添加如下内容之一:#coding:gbk#coding:utf-8##-*- coding : gbk -*-

    hello world python:

    #coding:utf-8
    '''
    Created on 2014-6-6
    
    @author: yzl
    '''
    
    print '----------基础类型的操作----------'
    i = 10
    print i
    i = i+10
    print i
    print i*2
    
    if i==20:
        print 'i==',i
        
    str = 'string '
    print str*2
    
    bool = True or False
    print bool
    
    s='this is test string 
    hello world python'
    print s
    
    l='''thi is test string
    test to print hello world python'''
    print l
    
    print '---------控制语句---------'
    
    # wait user input
    num = int(raw_input('Enter an integer :'))
    if num<10:
        print 'this number is < 10'
    elif num>=10 and num<=100:
        print 'this number is bettween 10 and 100'
    else:
        print 'yeah! the num is:',num
    for j in range(1,num):
        if j<5:
            continue
        if j>=10:
            break
        print 'for run :',j
    
    step = 0 
    while bool:
        if num<100:
            step = step +1
            print 'case 1,step is:',step
            if step > 10:
                break
        elif num>=100:
            bool = False
            print 'case 2 to stop while'
    # 当bool为false时执行
    else:
        print 'go to else case'
            

    运行结果:

    ----------基础类型的操作----------
    10
    20
    40
    i== 20
    string string 
    True
    this is test string hello world python
    thi is test string
    test to print hello world python
    ---------控制语句---------
    Enter an integer :200
    yeah! the num is: 200
    for run : 5
    for run : 6
    for run : 7
    for run : 8
    for run : 9
    case 2 to stop while
    go to else case
    
    
    Enter an integer :30
    this number is bettween 10 and 100
    for run : 5
    for run : 6
    for run : 7
    for run : 8
    for run : 9
    case 1,step is: 1
    case 1,step is: 2
    case 1,step is: 3
    case 1,step is: 4
    case 1,step is: 5
    case 1,step is: 6
    case 1,step is: 7
    case 1,step is: 8
    case 1,step is: 9
    case 1,step is: 10
    case 1,step is: 11
  • 相关阅读:
    bzoj1014: [JSOI2008]火星人prefix
    bzoj1934: [Shoi2007]Vote 善意的投票&&bzoj2768:[JLOI2010]冠军调查
    bzoj2705: [SDOI2012]Longge的问题
    bzoj4653: [Noi2016]区间
    bzoj2456: mode
    bzoj5018: [Snoi2017]英雄联盟
    关于树论【左偏树】
    caioj1522: [NOIP提高组2005]过河
    caioj1421&&hdu2167: [视频]【状态压缩】选数
    Linux下全局安装composer方法
  • 原文地址:https://www.cnblogs.com/yangzhilong/p/3772649.html
Copyright © 2011-2022 走看看