标签:otl frame c++ inline 区分 打印 外观 发行版 pen

./hello.py ,那么就需要在 hello.py 文件的头部指定解释器,如下:/hello.py 即可。



|
1
2
3
4
5
6
7
|
1、下载安装包 https://www.python.org/downloads/2、安装 默认安装路径:C:\python273、配置环境变量 【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用 ; 分割】 如:原来的值;C:\python27,切记前面有分号 |
|
1
2
3
|
无需安装,原装Python环境 ps:如果自带2.6,请更新至2.7 |
|
1
|
print("Hello World!") |
|
1
2
3
|
localhost:~ jieli$ vim hello.pylocalhost:~ jieli$ python hello.pyHello World! |
|
1
2
3
|
#!/usr/bin/env python print "hello,world" |
|
1
2
3
4
5
6
|
localhost:~ jieli$ pythonPython 2.7.10 (default, Oct 23 2015, 18:05:06)[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> print("Hello World!")Hello World! |
python解释器在加载 .py 文件中的代码时,会对内容进行编码(默认ascill)
ASCII(American Standard Code for Information Interchange,美国标准信息交换代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英语和其他西欧语言,其最多只能用 8 位来表示(一个字节),即:2**8 = 256-1,所以,ASCII码最多只能表示 255 个符号。
关于中文
为了处理汉字,程序员设计了用于简体中文的GB2312和用于繁体中文的big5。
GB2312(1980年)一共收录了7445个字符,包括6763个汉字和682个其它符号。汉字区的内码范围高字节从B0-F7,低字节从A1-FE,占用的码位是72*94=6768。其中有5个空位是D7FA-D7FE。
GB2312 支持的汉字太少。1995年的汉字扩展规范GBK1.0收录了21886个符号,它分为汉字区和图形符号区。汉字区包括21003个字符。2000年的 GB18030是取代GBK1.0的正式国家标准。该标准收录了27484个汉字,同时还收录了藏文、蒙文、维吾尔文等主要的少数民族文字。现在的PC平台必须支持GB18030,对嵌入式产品暂不作要求。所以手机、MP3一般只支持GB2312。
从ASCII、GB2312、GBK 到GB18030,这些编码方法是向下兼容的,即同一个字符在这些方案中总是有相同的编码,后面的标准支持更多的字符。在这些编码中,英文和中文可以统一地处理。区分中文编码的方法是高字节的最高位不为0。按照程序员的称呼,GB2312、GBK到GB18030都属于双字节字符集 (DBCS)。
有的中文Windows的缺省内码还是GBK,可以通过GB18030升级包升级到GB18030。不过GB18030相对GBK增加的字符,普通人是很难用到的,通常我们还是用GBK指代中文Windows内码。
Unicode(统一码、万国码、单一码)是一种在计算机上使用的字符编码。Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进制编码,规定虽有的字符和符号最少由 16 位来表示(2个字节),即:2 **16 = 65536,
注:此处说的的是最少2个字节,可能更多
UTF-8,是对Unicode编码的压缩和优化,他不再使用最少使用2个字节,而是将所有的字符和符号进行分类:ascii码中的内容用1个字节保存、欧洲的字符用2个字节保存,东亚的字符用3个字节保存...
所以,python解释器在加载 .py 文件中的代码时,会对内容进行编码(默认ascill),如果是如下代码(python2)的话:
报错:ascii码无法表示中文
|
1
2
3
|
#!/usr/bin/env python print "你好,世界" |
改正:应该显示的告诉python解释器,用什么编码来执行源代码,即:
|
1
2
3
4
|
#!/usr/bin/env python# -*- coding: utf-8 -*- print "你好,世界" |
注释:
单行注释:# 被注释内容
多行注释:""" 被注释内容 """
格式化输出:(三种方式)
1)
name = input("name:") #raw_input 适用于pytho2.X input 适用于pytho3.x
age = int(input("age:")) #int=intteger 整形
print(type(age) ,type( str(age)) )
job = input("job:")
salary = input("salary:")
info=‘‘‘
-----------info of %s---------
name:%s
age:%d
job:%s
salary:%s
‘‘‘% (name,name,age,job,salary)
print(info)
%s:string 字符
%d:整数
%f:浮点
打印字符类型
print(type(age))
name = input("name:") #raw_input 适用于pytho2.X input 适用于pytho3.x3)
age = int(input("age:")) #int=intteger 整形
job = input("job:")
salary = input("salary:")
info2=‘‘‘
-----------info2 of {_name}---------
name:{_name}
age:{_age}
job:{_job}
salary:{_salary}
‘‘‘.format(_name=name,
_age=age,
_job=job,
_salary=salary)
print(info2)
name = input("name:") #raw_input 适用于pytho2.X input 适用于pytho3.x
age = int(input("age:")) #int=intteger 整形
job = input("job:")
salary = input("salary:")
info3=‘‘‘
-----------info3 of {0}---------
name:{0}
age:{1}
job:{2}
salary:{3}
‘‘‘.format(name,age,job,salary)
print(info3)
九、模块初识
import sys
print(sys.path) #打印环境变量
import sys
print(sys.argv) #打印相对路径
import sys
print(sys.argv[2])
import os
os.system("dir")
import os
cmd_res = os.system("dir") #执行命令,不保存结果
print("-->",cmd_res)
import os
cmd_res = os.popen("dir").read() #os.popen 将显示结果放到内存中 还需要再用read将其显示出来
print("-->",cmd_res)
import login

|
1
2
3
4
|
name = "alex"print "i am %s " % name #输出: i am alex |
PS: 字符串是 %s;整数 %d;浮点数%f
|
1
2
3
|
name_list = [‘alex‘, ‘seven‘, ‘eric‘]或name_list = list([‘alex‘, ‘seven‘, ‘eric‘]) |
基本操作:
|
1
2
3
|
ages = (11, 22, 33, 44, 55)或ages = tuple((11, 22, 33, 44, 55)) |
|
1
2
3
|
person = {"name": "mr.wu", ‘age‘: 18}或person = dict({"name": "mr.wu", ‘age‘: 18}) |
常用操作:







#!/usr/bin/python a = 60 # 60 = 0011 1100b = 13 # 13 = 0000 1101c = 0 c = a & b; # 12 = 0000 1100print "Line 1 - Value of c is ", c c = a | b; # 61 = 0011 1101print "Line 2 - Value of c is ", c c = a ^ b; # 49 = 0011 0001 #相同为0,不同为1print "Line 3 - Value of c is ", c c = ~a; # -61 = 1100 0011print "Line 4 - Value of c is ", c c = a << 2; # 240 = 1111 0000print "Line 5 - Value of c is ", c c = a >> 2; # 15 = 0000 1111print "Line 6 - Value of c is ", c
import getpass #import为python的标准库
username = input("username:")
password = getpass.getpass("password:")
print(username,password)
_username = ‘lv‘
_password = ‘123‘
username = input("username:")
password = input("password:")
if _username == username and _password == password:
print("Welecom user {name} login..".format(name=username))
else:
print("Invalid username or password!")

age_of_oldboy = 56
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("yes,you got it.")
elifguess_age > age_of_oldboy :
print("think smaller...")
else:
print("think bigger!")
十四、while循环
最简单的while循环:
count = 0
while True:
print("count:",count)
count = count +1 #count +=1
if count == 1000:
break
猜三次,三次都错就结束: 涉及到while循环
猜年龄 while:
age_of_oldboy = 56
while True:
if count ==3 :
break
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("yes,you got it!")
break
elif guess_age >age_of_oldboy :
print("think smaller...")
else:
print("think bigger...")
count +=1
age_of_oldboy = 56
count = 0
while count <3:
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("yes,you got it!")
break
elif guess_age >age_of_oldboy :
print("think smaller...")
else:
print("think bigger...")
count +=1
else :
print("you have tried too many times.. fuck off")
for i in range(10):
print("loop ",i)
猜年龄 for:
age_of_oldboy = 56
count = 0
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("yes,you got it!")
break
elif guess_age >age_of_oldboy :
print("think smaller...")
else:
print("think bigger...")
count +=1
else :
print("you have tried too many times.. fuck off")
age_of_oldboy = 56
count = 0
# while count <3: while和for都可以
for i in range(4):
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("yes,you got it!")
break
elif guess_age >age_of_oldboy :
print("think smaller...")
else:
print("think bigger...")
count +=1
if count == 3:
continue_confirm = input("do you want to keep guessing?")
if continue_confirm != ‘n‘:
count = 0
for i in range(1,10,2):
print("loop ",i)
for i in range(0,10):
if i<5:
print("loop",i)
else:
continue
print("hehe")
break:
for i in range(10):
print(‘-------------‘,i)
for j in range(10):
print(j)
if j>5:
break
作业二:编写登陆接口
result=值1if条件else值2
如果条件为真:result = 值1
如果条件为假:result = 值2
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">
标签:otl frame c++ inline 区分 打印 外观 发行版 pen
原文地址:http://www.cnblogs.com/Dnalv110/p/7424404.html