一.Python安装与初识
发布日期:2021-05-07 00:20:07 浏览次数:22 分类:技术文章

本文共 2456 字,大约阅读时间需要 8 分钟。

 Python安装与初识

  Python初识

    python的优势开发效率高

                    劣势执行效率低

    python的种类:JPython ,CPython ,pypy

 

 

 

    python之禅:(自行谷歌翻译)

>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity, refuse the temptation to guess.There should be one-- and preferably only one --obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!

                          

python安装

    Windows安装:

   1.

   2.在本地安装

   3.设置环境变量

        右键-> 我的电脑 -> 属性 -> 高级系统设置 -> 环境变量 -> 系统变量 -> Path -> 新建 -> python软件下bin文件夹

   4.cmd测试

 python编译python文件

#a.py为python代码文件python a.py

 

 

   Linux安装: 

          yum 安装     yum install python

          apt安装        apt-get install python

          ......

 python基础

           变量   

//一:字符串   //四种形式字符串   //1   name='Hello World!'   //2   name="Hello World!"     //3   name="""Hello World!"""   //4   name='''Hello World!'''//二:数字   num=123

           输出                       

//控制台输出    print("Hello World!")  //控制台变量输出  name="Hello World!"  print(name)

 

              输入

//控制台输入    num=input("请输入你的年龄?")//输出年龄     print("我的年龄是%d"%(int(num)));

 

 逻辑判断

       if

//if作用是判断age=input("请输入你的年龄?")if age < 12 :    print("儿童")elif age < 18 :        print("少年")else :        print("青年")

 

 循环

         while

//while循环#coding=gbknum=1while num < 10:	print("循环第%d次!"%(num))	num = num + 1

 

         for

#coding=gbk//for range()循环数字for i in range(10):	print(i)//for循环字符串for i in "Hello World!":		print(i)

Test

从1循环到100

#coding=gbk'''从1循环到10'''for i in range(100):    print(i)

 从1加到100

#coding=gbk''' 1+2+3+....+100 '''num=0for i in range(100):    num+=iprint(num)

 1-2+3-4+5-6+....-100

#coding=gbk''' 1-2+3-4+...-100 '''num = 0for i in range(100):    if i % 2 == 0 :                num=num-i        else:                num=num+iprint(num)

用户登录,三次机会重试 

#coding=gbk'''用户登录,三次机会重试 '''num = 0while num < 3:    user_name = input("请输入用户名:")    if user_name == "tom" :            print("登陆成功!")                num=3        else :                print("登陆失败!")                                num = num + 1         print("还有%d次机会!"%(3-num))

 

 

 

上一篇:搭建git服务器远程仓库_linux
下一篇:Linux Vim操作-添加行号

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年03月15日 10时55分53秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章