zoukankan      html  css  js  c++  java
  • 初学Python

    #输入
    try: userimput = input("Say something: ") #PyDev
    except NameError: pass
    print(userimput);
    

      

    #coding=utf-8 程序文件编码格式UTF-8中文显示不会乱码
    #Python 3.4  https://docs.python.org/3.4/library/
    #IDE:Visual Studio 2015  Window10
    import atexit
    import os
    import unicodedata
    import sys
    import time
    import unicodedata
    import winsound
    import code
    import codecs
    import math
    
    print ("hello word");
    print (sys.platform);
    print (2 ** 100);
    #输入
    try: input = raw_input
    except NameError: pass
    print("Hi " + input("Say something: "));
    #中文
    #sys.stdout = io.TextIOWrapper(sys.stdout.buffer, errors = 'replace', line_buffering = True)
    #try:
        #reload(sys)
        #sys.setdefaultencoding('utf-8')
    #except:
       #pass
    print("中国人解放军");
    
    #字典
    #x={"a":"中国","b":"好","c":12}
    #print(x["a"]);
    #print(x["b"]);
    #print(x["c"]);
    #for key in x:print("Key is %s and value is %s"%(key,x[key]));
    
    age=25;
    name="涂聚文";
    print("%s is %d years old 多少岁了" % (name, age));
    #序列的基本操作包括:索引(indexing)、分片(slicing)、加(adding)、乘(multiplying)以及成员检查,以下都以列表为例
    #序列是python中最基本的数据结构,python中包含6种内建的序列,分别是列表、元组、字符串、Unicode字符串、buffer对象和xrange对象。
    #定义元组
    #根据给定的年月日以数字形式打印出日期
    months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    # 以1~31的数字作为结尾的列表
    endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 * ['th'] + ['st'];
    year = input('Year: ');
    month = input('Month(1-12): ');
    day = input('Day(1-31): ');
    month_number = int(month); #转成数字类型
    day_number = int(day);
    # 将月份和天数减1获得正确的索引
    month_name = months[month_number-1];#获取月名称
    ordinal = day + endings[day_number-1];#获日
    print(month_name + '月 ' + ordinal + ', ' + year+'年');
    for x in range(1, 11):print(repr(x).rjust(2), repr(x*x).rjust(3), end="
    ");#换行
    # 注意前一行 'end' 的使用
    print(repr(x*x*x).rjust(4))
    #
    for x in range(1, 11):print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x));
    #括号及其里面的字符 (称作格式化字段) 将会被 format() 中的参数替换
    print('{0} 和 {1}'.format('Google', 'Runoob'));
    print('{}网址: "{}!"'.format('中国', 'www.dusystem.com'));
    #如果在 format() 中使用了关键字参数, 那么它们的值会指向使用该名字的参数。
    print('{name}网址: {site}'.format(name='涂聚文', site='www.dusystem.com'));
    print('常量 PI 的值近似为: {}。'.format(math.pi));
    print('常量 PI 的值近似为: {!r}。'.format(math.pi));
    print('常量 PI 的值近似为 {0:.3f}。'.format(math.pi));
    table = {'Google': 1, 'Runoob': 2, 'Taobao': 3};
    #在 ':' 后传入一个整数, 可以保证该域至少有这么多的宽度。 用于美化表格时很有用。
    for name, number in table.items():print('{0:10} ==> {1:10d}'.format(name, number));
    table = {'Google': 1, 'Runoob': 2, 'Taobao': 3}
    print('Runoob: {0[Runoob]:d}; Google: {0[Google]:d}; Taobao: {0[Taobao]:d}'.format(table));
    #r以只读方式打开文件。文件的指针将会放在文件的开头。这是默认模式。
    #rb以二进制格式打开一个文件用于只读。文件指针将会放在文件的开头。这是默认模式。
    #r+打开一个文件用于读写。文件指针将会放在文件的开头。
    #rb+以二进制格式打开一个文件用于读写。文件指针将会放在文件的开头。
    #w打开一个文件只用于写入。如果该文件已存在则将其覆盖。如果该文件不存在,创建新文件。
    #wb以二进制格式打开一个文件只用于写入。如果该文件已存在则将其覆盖。如果该文件不存在,创建新文件。
    #w+打开一个文件用于读写。如果该文件已存在则将其覆盖。如果该文件不存在,创建新文件。
    #wb+以二进制格式打开一个文件用于读写。如果该文件已存在则将其覆盖。如果该文件不存在,创建新文件。
    #a打开一个文件用于追加。如果该文件已存在,文件指针将会放在文件的结尾。也就是说,新的内容将会被写入到已有内容之后。如果该文件不存在,创建新文件进行写入。
    #ab以二进制格式打开一个文件用于追加。如果该文件已存在,文件指针将会放在文件的结尾。也就是说,新的内容将会被写入到已有内容之后。如果该文件不存在,创建新文件进行写入。
    #a+打开一个文件用于读写。如果该文件已存在,文件指针将会放在文件的结尾。文件打开时会是追加模式。如果该文件不存在,创建新文件用于读写。
    #ab+以二进制格式打开一个文件用于追加。如果该文件已存在,文件指针将会放在文件的结尾。如果该文件不存在,创建新文件用于读写。
    # 打开一个文件
    #f = open("foo.txt", "w");
    #f.write( "Python 是一个非常好的语言。
    是的,的确非常好!!
    涂聚文
    2013" );#写内容
    # 关闭打开的文件
    #f.close();
    # 打开一个文件
    f = open("foo.txt", "r");
    str = f.read();#读文件
    print(str);
    # 关闭打开的文件
    f.close();
    #while 循环 
    n = 100;
    sum = 0;
    counter = 1;
    while counter <= n:
        sum = sum + counter
        counter += 1
    print("1 到 %d 之和为: %d" % (n,sum));
    #
    sites = ["Bing", "Google","Phthon","Dusystem"]
    for site in sites:
        if site == "Phthon":
            print("Phthon教程!")
            break
        print("循环数据 " + site)
    else:
        print("没有循环数据!")
    print("完成循环!")
    

     

     Eclipse/Java/Python

     http://www.pydev.org/manual_101_install.html

    visual studio 2017 已经集成了:

    Anaconda Enterprise 5

    https://www.anaconda.com/

    安装在

    C:Program Files (x86)Microsoft Visual StudioSharedPython36_64

    C:Program Files (x86)Microsoft Visual StudioSharedAnaconda3_64

    https://github.com/Microsoft/PTVS/

    import sys;
    import math;
    
    
    global dufu;
    
    def printdebug(func):
        def __decorator(x,y):    #add parameter
            print('enter the num')
            result =func(x,y)  #pass 
            print('exit the num')
            return result
        return __decorator 
    
    
    @printdebug #Decorator装饰器
    def dufu(x,y):
        print ('hi,geovindu');
        return x+y
    
    
    a=dufu(2,5);
    print(a);
    
  • 相关阅读:
    cd 好吃的 收藏
    2011 无代码无意义…test 指针 v1
    转 云中漫步的 电子书 from simon
    2011无代码无意义 test_gets_scanf连用 等
    svn—relocate 的原因
    转 CString,string,char*的综合比较
    2011 无代码无意义 test_内存之 变量的边界 (图)
    转 解决"应用程序配置不正确,程序无法启动"
    转 删除已存在的SVN账户信息
    C#中IO类FileInfo和Directory操作实例
  • 原文地址:https://www.cnblogs.com/geovindu/p/6144516.html
Copyright © 2011-2022 走看看