• 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
  • 相关阅读:
    MySql面试题、知识汇总、牛客网SQL专题练习
    产生过拟合的原因
    《人类简史》这本烧脑书风靡全球的秘密是什么?
    厌食?暴食?试试这个 VR 新疗法
    协程、异步IO
    进程池
    进程(同步)锁
    特朗普变脸:同媒体“友好会谈”,怨媒体“死不悔改”
    多进程Queue
    redis 在 php 中的应用(事务 [ Transaction ] 篇)
  • 原文地址:https://www.cnblogs.com/yangzhilong/p/3772649.html
Copyright © 2020-2023  润新知