标签:down 安装 范围 important 扩展 对象 cep 计算机程序 用户输入
Python的创始人为Guido van Rossum。1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,做为ABC 语言的一种继承。之所以选中Python(大蟒蛇的意思)作为该编程语言的名字,是因为他是一个叫Monty Python的喜剧团体的爱好者 。

由上图可见,python语言使用率呈上升趋势,而排名前三的语言使用率呈下降趋势。
优点:
缺点:
1、下载安装包 https://www.python.org/downloads/ 2、安装 安装在C:\Python36 3、配置环境变量 【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用;分割】
1.解压 tar xf Python-3.6.2.tgz 2.编译安装 cd Python-3.6.2 ./configure --prefix=/usr/local/Python3.6 make make install 3.配置环境变量 vim /etc/profile PATH=/usr/local/Python3.6/bin:$PATH source /etc/profile 4.测试 python3.6
打开pycharm,新建python项目,新建python文件。
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
print("hello,world")
变量来源于数学,是计算机语言中能储存计算结果或能表示值抽象概念。变量可以通过变量名访问。在指令式语言中,变量通常是可变的;但在纯函数式语言(如Haskell)中,变量可能是不可变(immutable)的。在一些语言中,变量可能被明确为是能表示可变状态、具有存储空间的抽象(如在Java和Visual Basic中);但另外一些语言可能使用其它概念(如C的对象)来指称这种抽象,而不严格地定义“变量”的准确外延。
声明变量
#!/usr/binl/env python #encoding: utf-8 #author: YangLei name = "yanglei" print(name)
上述代码声明了一个变量,变量名为: name,变量name的值为:"yanglei"
变量定义的规则:
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
input_name = input("Please enter your name: ")
print("hi,%s" % input_name)
1、数字
int(整型)
"hello world"
字符串拼接:
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
name = "yanglei"
print("hi,%s" % name)
#输出hi,yanglei
注:字符串是 %s;整数 %d;浮点数%f
#!/usr/binl/env python #encoding: utf-8 #author: YangLei name = ["yanglei","jack","marry","andy"]
基本操作:
5、字典(无序)
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
user_info = {"name":"yanglei","age":23,"job":"IT"}
常用操作:

比较运算:

赋值运算:

逻辑运算:

成员运算:

身份运算:

位运算:

运算符优先级:

场景一、用户登陆验证
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
input_user = input("Please enter your user name: ")
input_password = input("Please enter your password: ")
if input_user == "yanglei" and input_password == "123456":
print("\033[32;1m%s login successfully\33[0m" % input_user)
else:
print("\033[31;1mThe user name or password error,please try again\033[0m")
场景二、猜年龄游戏
在程序里设定好你的年龄,然后启动程序让用户猜测,用户输入后,根据他的输入提示用户输入的是否正确,如果错误,提示是猜大了还是小了
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
guess_age = 50
input_age = int(input("Please enter your guess age: "))
if input_age > guess_age:
print("\033[31;1mCan you guess what big\33[0m")
elif input_age < guess_age:
print("\033[31;1mCan you guess what small\33[0m")
else:
print("\033[32;1mYou guessed it\33[0m")
外层变量,可以被内层代码使用
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
count = 1
while count <= 10:
if count == 5:
count += 1
continue
print(count)
count += 1
#!/usr/binl/env python
#encoding: utf-8
#author: YangLei
count = 1
while count <= 10:
if count == 5:
count += 1
break
print(count)
count += 1
由此可以看出continue是跳出当前循环,而break是跳出本层循环。
场景一、用户登陆验证升级
#!/usr/bin/env pyhon
#encoding: utf-8
#auth: yanglei
count = 0
while count < 3:
input_user = input("Please enter your user name: ")
input_password = input("Please enter your password: ")
if input_user == "yanglei" and input_password == "123456":
print("\033[32;1m%s login successfully\33[0m" % input_user)
break
elif count == 2:
print("\033[31;1mThe user name or password mistake,three chances to use up,the program exits\33[0m")
break
else:
count += 1
print("\033[31;1mThe user name or password error,please try again\033[0m")
场景二、猜年龄游戏升级
#!/usr/bin/env pyhon
#encoding: utf-8
#auth: yanglei
guess_age = 50
count = 0
while count <= 3:
if count == 3:
input_choose = input("Do you want to continue to play?(Y or y|N or n)")
if input_choose == "Y" or input_choose == "y":
count = 0
continue
elif input_choose == "N" or input_choose == "n":
break
else:
print("\033[31;1mAre you input errors!\33[0m")
continue
input_age = int(input("Please enter your guess age: "))
if input_age > guess_age:
print("\033[31;1mCan you guess what big\33[0m")
count += 1
elif input_age < guess_age:
print("\033[31;1mCan you guess what small\33[0m")
count += 1
else:
print("\033[32;1mYou guessed it\33[0m")
break
标签:down 安装 范围 important 扩展 对象 cep 计算机程序 用户输入
原文地址:http://www.cnblogs.com/00doudou00/p/7115218.html