文章汇总:https://www.cnblogs.com/dotnetcrazy/p/9160514.html
<https://www.cnblogs.com/dotnetcrazy/p/9160514.html>

多图旧排版:https://www.cnblogs.com/dunitian/p/9103673.html
<https://www.cnblogs.com/dunitian/p/9103673.html>

VSCode设置python3的开发环境(linux下默认是python2)
https://www.cnblogs.com/dotnetcrazy/p/9095793.html
<https://www.cnblogs.com/dotnetcrazy/p/9095793.html>

欢迎提出更简单的语法~(文章中案例有两个福利哦,一个是养生,一个是人工智能[ 密码:fqif])

先说下感觉,python的编程有点JavaScript
的感觉(比如:'和“有时候不区别),又感觉像外国版的易语言,整个过程像读书一样,比如一个元素不在列表之中==>for item not in lists
。使用它做个大点的项目一定要先规定好编程风格,不然能让人崩溃的。先不深究,后面会继续深究。。。(Python2我就不讲了,官方推荐使用Python3)
 
1.命名规则¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#1.命名规则>

Python官方是推荐使用_来间隔单词,但一般开发人员都是以各自主语言的命名来定义的,这个就各人爱好了,不过团队一定要统一。

命名规则:总的原则就是 见名知意,一般都是 驼峰命名法,纯Python的话推荐用 _连接单词

扩充:Python的关键词可以自己打印一下:
In [1]: import keyword print(keyword.kwlist)   ['False', 'None', 'True',
'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in',
'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']  
1.1.标识符¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#1.1.标识符>

标示符由字母、下划线和数字组成,且数字不能开头(这个基本上都一样)注意:标识符是区分大小写的

1.2.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#1.2.Python>
In [2]: # Python标识符区分大小写的案例 temp="xxx" tEmp="===" print(temp+tEmp)   xxx===  
1.3.CSharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#1.3.CSharp>
In [3]: %%script csharp //CSharp标识符区分大小写的案例 var temp = "xxx"; var tEmp =
"==="; Console.WriteLine(temp + tEmp);   xxx===  
2.注释¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#2.注释>

2.1.python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#2.1.python>

python输出就直接print即可,C是printf(不要搞混哦)

#注释一行,三个单引号或者三个双引号 注释多行:'''XXX'''或者"""XXXX"""(一般用#就够了,有点像shell脚本的感觉)
In [4]: #单行注释 输出 print("Hello World!")   Hello World! In [5]: '''三个单引号多行注释:
print("Hello World!") print("Hello World!") print("Hello World!")''' Out[5]:
'三个单引号多行注释:\nprint("Hello World!")\nprint("Hello World!")\nprint("Hello
World!")' In [6]: """三个双引号多行注释: print("Hello World!") print("Hello World!")
print("Hello World!")""" Out[6]: '三个双引号多行注释:\nprint("Hello
World!")\nprint("Hello World!")\nprint("Hello World!")'  
2.2.CSharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#2.2.CSharp>

C、Java、Net都是//注释一行,/**/注释多行
Console.WriteLine("小明同学"); // Console.WriteLine("小明同学"); 注释一行
/*Console.WriteLine("小明同学"); Console.WriteLine("小明同学"); 注释多行*/  
3.变量¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#3.变量>

3.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#3.1.Python>

python定义变量比较牛逼,直接写变量名即可,句子后面 不用加分号,eg:name="小明"
In [7]: #定义一个变量并输出 name="小明" print(name)   小明  
3.2.CSharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#3.2.CSharp>

可以用var来进行类型推断,eg:var name="小明";
In [8]: %%script csharp var test = "123";//定义一个变量
Console.WriteLine(test);//输出这个变量   123  
4.输入输出¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#4.输入输出>

4.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#4.1.Python>

换行输出,不换行输出:(\n使用这个就不说了,它们和C都是一样的)

python:print("dnt.dkill.net/now",end='') 默认end='\n' (' 和 " 随意)
In [9]: print("dnt.dkill.net/now",end='') print("带你走进中医经络")  
dnt.dkill.net/now带你走进中医经络 In [10]: print("dnt.dkill.net/now",end="") print(
"带你走进中医经络")   dnt.dkill.net/now带你走进中医经络  
如果字符串内部既包含'又包含"怎么办?可以用转义字符\来标识
In [11]: #如果字符串内部既包含'又包含"怎么办?可以用转义字符\来标识 print("I\'m \"OK\"!")   I'm "OK"!  
r''表示''内部的字符串默认不转义
In [12]: # 如果字符串里面有很多字符都需要转义,就需要加很多\,为了简化,Python还允许用r''表示''内部的字符串默认不转义 print(r'
\\\t\\')   \\\t\\  
'''...'''的格式表示多行内容
In [13]: #如果字符串内部有很多换行,用\n写在一行里不好阅读,为了简化,Python允许用'''...'''的格式表示多行内容 print(
'''我请你吃饭吧~ 晚上吃啥? 去厕所,你说呢?''')   我请你吃饭吧~ 晚上吃啥? 去厕所,你说呢?  
扩:Python提供一种以空格分隔的方式:
In [14]: print("I","Love","You")   I Love You  
python输出多个重复字符,不需要自己手打N个*或者for循环输出多个重复字符,eg:print("x"*10)
In [15]: print("x"*10)   xxxxxxxxxx  
如果你不太确定应该用什么,%s永远起作用,它会 把任何数据类型转换为字符串
%c 字符 %s 通过str() 字符串转换来格式化 %o 八进制整数 %x 十六进制整数(小写字母) %X 十六进制整数(大写字母) %e
指数(小写'e') %E 指数(大写“E”) %f 浮点实数 %g %f和%e 的简写 %G %f和%E的简写  
下面来个输入输出的简单的 案例吧:打印一张名片,Name:毒逆天,Gender:男

print("Name:%s,Gender:%s"%(name,gender))【注意引号后面没有,哦】
In [16]: #定义一个变量name,用户输入将赋值给name name=input("请输入用户名:")
#定义一个变量gender,用户输入将赋值给gender gender=input("请输入性别:") #多个变量输出 print("Name:%s
,Gender:%s"%(name,gender))   请输入用户名:毒逆天 请输入性别:男 Name:毒逆天,Gender:男  
4.2.CSharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#4.2.CSharp>

输出用:Console.Write Console.WriteLine
In [17]: %%script csharp Console.Write("dnt.dkill.net/now");
Console.WriteLine("带你走进中医经络");   dnt.dkill.net/now带你走进中医经络  
C#用@来转义字符,不管你是转义字符还是换行,通杀
In [18]: %%script csharp Console.WriteLine(@"\\\\\\\");   \\\\\\\ In [19]: %%
script csharp Console.WriteLine(@"我请你吃饭吧~ 晚上吃啥? 去厕所,你说呢?")   我请你吃饭吧~ 晚上吃啥?
去厕所,你说呢?  
Csharp输入输出的简单的 案例:打印一张名片,Name:毒逆天,Gender:男

C#:Console.WriteLine($"Name:{name},Gender:{gender}");
Console.WriteLine("请输入用户名:"); var name = Console.ReadLine(); Console.WriteLine(
"请输入性别:"); var gender = Console.ReadLine(); Console.WriteLine($
"Name:{name},Gender:{gender}"); //推荐用法 Console.WriteLine("Name:{0},Gender:{1}",
name, gender); //Old 输出  
5.类型转换¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#5.类型转换>

5.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#5.1.Python>

类型(值),eg:int(),long(),float(),str(),list(),set()...等等

Python没有 double类型哦~

扩:转换成 16进制:hex()、转换为 8进制:oct()
In [20]: # 求和 num1=input("输入第一个数字") num2=input("输入第二个数字") print("num1+num2=%d"
%(int(num1)+int(num2)))   输入第一个数字1 输入第二个数字2 num1+num2=3  
5.2.Csharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#5.2.Csharp>

C#:该案例推荐使用 int.TryParse,我这边就用常用的Convert系列了【支持类型比较多】

Convert.ToInt64(),Convert.ToDouble(),Convert.ToString()...
//类型转换 Console.WriteLine("输入第一个数字:"); var num1 = Console.ReadLine(); Console.
WriteLine("输入第二个数字:"); var num2 = Console.ReadLine(); Console.WriteLine($
"num1+num2={Convert.ToInt32(num1) + Convert.ToInt32(num2)}");  
6.算术运算符¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#6.算术运算符>

6.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#6.1.Python>

算术运算符编程语言基本上差不多,Python多了个 // 取商(%是取余)和 幂**,来个案例:
In [21]: num=9 print("num=9,下面结果是对2的除,取余,取商操作:") print(num/2.0) print(num%2.0)
print(num//2.0) print("2^3=%d"%2**3)   num=9,下面结果是对2的除,取余,取商操作: 4.5 1.0 4.0
2^3=8  
Python3现在这样写也行,推荐和其他语言写法一致(不然你用惯了Python,切换的时候会出事的)
In [22]: num=9 print("num=9,下面结果是对2的除,取余,取商操作:") print(num/2) print(num%2)
print(num//2) print("2^3=%d"%2**3)   num=9,下面结果是对2的除,取余,取商操作: 4.5 1 4 2^3=8  
+= -= *= /= %= **= //= 这些就不用详说了吧?

举个例子:c += a 等效于 c = c + a

注意下,Python中不见得等效,Python都是引用,这个先不说后面说
 
6.2.Csharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#6.2.Csharp>

C#常用数学方法都在Match类中
In [23]: %%script csharp var num=9;
Console.WriteLine("num=9,下面结果是对2的除,取余,取商操作:") Console.WriteLine(num/2.0);
Console.WriteLine(num%2.0); Console.WriteLine(num/2);
Console.WriteLine(Math.Pow(2,3));   num=9,下面结果是对2的除,取余,取商操作: 4.5 1 4 8  
7.if else¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#7.if-else>

7.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#7.1.Python>

说Python像外国版的易语言,这边就可以看出来一点了,如果再结合Python命名规则就感觉在阅读文章一样

先说说Python的逻辑运算符:与and 或or 非not,这个倒是跟C、C#、Java等大大不同,和SQL倒是差不多

关系运算符和其他语言基本上差不多(== != <> > < >= <=)

就一点不一样:不等于也可以用<>,这是兼容SQL的写法吗?

来个if else基础语法:括号可加可不加,但是记得加:。不用大括号,但是if里面的代码注意缩进
In [24]: age=19 if age>=18: print("成年了")   成年了  
再来个嵌套的:注意哦~ else if 在python里面 简写成了:elif
In [25]: age=24 if age>=23: print("七大姑曰:工作了吗?八大姨问:买房了吗?异性说:结婚了吗?") elif age>=18
: print(age) print("成年了哇") else: print("好好学习天天向上")  
七大姑曰:工作了吗?八大姨问:买房了吗?异性说:结婚了吗?  
结合前面知识,再来个案例:
In [26]: input_int=int(input("请输入(1-7)")) #if后面的:,tab格式,else if 现在是elif if
input_int==1: print("星期一") elif input_int==2: print("星期二") elif input_int==3:
print("星期三") elif input_int==4: print("星期四") elif input_int==5: print("星期五")
elif input_int==6: print("星期六") elif input_int==7: print("星期日") else: print("别闹"
)   请输入(1-7)2 星期二  
7.2.Csharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#7.2.Csharp>

C# if else 单行代码可以不用写括号
int age = 24; if (age >= 23) Console.WriteLine("七大姑曰:工作了吗?八大姨问:买房了吗?异性说:结婚了吗?"
); else if (age >= 18) { Console.WriteLine(age); Console.WriteLine("成年了哇"); }
else Console.WriteLine("好好学习天天向上");
NetCore现在推荐,如果是单行,建议Code和if else写在一行:
int age = 24; if (age >= 23) Console.WriteLine("七大姑曰:工作了吗?八大姨问:买房了吗?异性说:结婚了吗?"
); else if (age >= 18) { Console.WriteLine(age); Console.WriteLine("成年了哇"); }
else Console.WriteLine("好好学习天天向上");  
8.While¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#8.While>

8.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#8.1.Python>

python里面没有++ 和 --,这点的确用的有点小不方便,扩展部分有相关说明

while循环一般通过数值是否满足来确定循环的条件

来几个个案例(PS:感觉用C了,捂脸^_^)
In [28]: num=10 while num>0: print(num) num-=1   10 9 8 7 6 5 4 3 2 1 In [29]:
i=1 #输出一个三角形 while i<6: j=1 while j<=i: print("*",end="")#不换行输出 j+=1 print("")
#下一行 i+=1   * ** *** **** ***** In [30]: # 1~100求和 i=1 sum=0 while i<=100: sum+=
i i+=1 print(sum)   5050  
8.2.Csharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#8.2.Csharp>

用法差不多,来个案例
In [31]: %%script csharp int index = 1; int sum = 0; while (index <= 100) {
sum += index; index++; } Console.WriteLine(sum);   5050  
8.3.Python扩展(++ --)¶
<https://www.cnblogs.com/dotnetcrazy/p/9102030.html#8.3.Python扩展(++---)>

其实Python分为 可变类型(list,dict,set等等)和 不可变类型(int,str,tuple等等)

像数字这类的是不可变类型(后面会继续说)所以结果往往和你预期的不一样哦~看个案例:
In [32]: # python 中,变量是以内容为基准而不是像 c 中以变量名为基准,所以只要你的数字内容是5 # 不管你起什么名字,这个变量的 ID
是相同的,同时也就说明了 python 中一个变量可以以多个名称访问 a=5 b=5 print(id(a)) print(id(b)) print(a is
b) a+=1 print(id(a)) print(id(b)) print(a is b)   93994553510560 93994553510560
True 93994553510592 93994553510560 False  
你还可以看看这篇文章:Python没有 ++/-- 参考文章(点我)
<https://blog.csdn.net/somehow1002/article/details/73744626>
 
9.for¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#9.for>

9.1.Python¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#9.1.Python>

python的for循环,类似于js里面的for in

当然了,python的for还有很多诸如列表生成式的便捷功能,基础部分先不说

看个基础案例:
In [1]: # 基础循环:后面会讲range for i in range(5): print(i) i+=1   0 1 2 3 4 In [2]:
#while循环一般通过数值是否满足来确定循环的条件 #for循环一般是对能保存多个数据的变量,进行遍历 name=
"https://pan.baidu.com/s/1weaF2DGsgDzAcniRzNqfyQ#mmd" for i in name: if i=='#':
break print(i,end='')#另一种写法:print("%s"%i,end="") print('\n end ...')  
https://pan.baidu.com/s/1weaF2DGsgDzAcniRzNqfyQ end ...  
9.2.Csharp¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#9.2.Csharp>

foreach (var i in name)
In [3]: %%script csharp var url =
"https://pan.baidu.com/s/1weaF2DGsgDzAcniRzNqfyQ#mmd"; foreach (var item in
url) { if (item == '#') break; Console.Write(item); } Console.WriteLine("\n end
...");   https://pan.baidu.com/s/1weaF2DGsgDzAcniRzNqfyQ end ...  
9.3.Python扩展(for else)¶
<https://www.cnblogs.com/dotnetcrazy/p/9102030.html#9.3.Python扩展(for-else)>

for的扩展:for else(一般不太用)

官方参考:https://docs.python.org/3/reference/compound_stmts.html#the-for-statement
<https://docs.python.org/3/reference/compound_stmts.html#the-for-statement>



图片出处:https://www.cnblogs.com/dspace/p/6622799.html
<https://www.cnblogs.com/dspace/p/6622799.html>
 
其他扩展¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#其他扩展>

1.Python 没有 switch / case 语句¶
<https://www.cnblogs.com/dotnetcrazy/p/9102030.html#1.Python-没有-switch-/-case-语句>

Python 没有switch / case语句。为了实现它,我们可以使用字典映射:

官方的解释说:
https://docs.python.org/3.6/faq/design.html#why-isn-t-there-a-switch-or-case-statement-in-python

<https://docs.python.org/3.6/faq/design.html#why-isn-t-there-a-switch-or-case-statement-in-python>

"用if... elif... elif... else序列很容易来实现switch / case语句,而且可以使用函数字典映射和类的调度方法"
def numbers_to_strings(argument): switcher = { 0: "zero", 1: "one", 2: "two", }
return switcher.get(argument, "nothing")
这段代码类似于:
function(argument){ switch(argument) { case 0: return "zero"; case 1: return
"one"; case 2: return "two"; default: return "nothing"; }; };
在Python中字典映射也可以包含函数或者 lambda 表达式:
def zero(): return "zero" def one(): return "one" def
numbers_to_functions_to_strings(argument): switcher = { 0: zero, 1: one, 2:
lambda: "two", } func = switcher.get(argument, lambda: "nothing") return func()
类的调度方法:

如果在一个类中,不确定要使用哪种方法,可以用一个调度方法在运行的时候来确定
class Switcher(object): def numbers_to_methods_to_strings(self, argument):
method_name = 'number_' + str(argument) method = getattr(self, method_name,
lambda: "nothing") return method() def number_0(self): return "zero" def
number_1(self): return "one" def number_2(self): return "two"  
Python设计相关的为什么,可以参考官方文档:https://docs.python.org/3.6/faq/design.html
<https://docs.python.org/3.6/faq/design.html>
 
2.Csharp基础笔记¶ <https://www.cnblogs.com/dotnetcrazy/p/9102030.html#2.Csharp基础笔记>

C#基础(逆天上学那会做的笔记)

易忘知识点
<https://images2018.cnblogs.com/blog/658978/201806/658978-20180607154628616-1225096525.jpg>

C#基础汇总
<https://images2018.cnblogs.com/blog/658978/201806/658978-20180607154702861-1611313816.jpg>

异常概况系
<https://images2018.cnblogs.com/blog/658978/201806/658978-20180607155437373-1409607729.png>

其实有了Code,笔记也就没啥用了,知识点直接Code验证一下即可

CodeBase ~ POP
<https://github.com/dunitian/LoTCodeBase/tree/master/NetCode/1.面向过程>

CodeBase ~ OOP
<https://github.com/dunitian/LoTCodeBase/tree/master/NetCode/2.面向对象>
 
欢迎纠正+补充~

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信