初学Python

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

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#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="\n");#换行
# 注意前一行 '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 是一个非常好的语言。\n是的,的确非常好!!\n涂聚文\n2013" );#写内容
# 关闭打开的文件
#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 Studio\Shared\Python36_64

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64

 

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);

 

posted @   ®Geovin Du Dream Park™  阅读(443)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示