python1day
下载地址 https://www.python.org/downloads/
一 配置环境变量
右键计算机--属性--高级系统设置-高级-环境变量-系统变量--Administratorpath编辑-
添加
C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\Scripts\
C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\Scripts\
C:\Python27\
C:\Python27\Scripts
二 在windows打python 程序
创建一个文件 改成.py文件 编辑 print “hello word!”
cmd
进入d: 运行xx.py
三 在乌版图系统中vim 编辑一个文件
#!/usr/bin/python
#!/usr/bin/env python 系统默认最高级python 版本
print ("hello")
print ("cc\ndd") \n 是换行符
四 命名的规则
变量定义的规则:
- 变量名只能是 字母、数字或下划线的任意组合
- 变量名的第一个字符不能是数字
- 以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
son_of_twins_gf
SonOfTwinaGf 只能2种选其一
五 python注释
当行注视:# 被注释内容
多行注释:""" 注释内容 """
六 用户输入
python 3 user_name = input("what your name")
python 2.7 user_name=raw_input("what your name")
python 2.7 input 申明变量
name = jack #先赋予变量
user_name=input("what your name")
what your name name # 显示出what your name 输入 name
print (user_name) # 打印 user_name
jack
七 替换
name = input("what your name:")
age = input("how old you:") #%d int(input("how old you")) #%f 代表浮点 例如3.000
work = input("what are you doning:")
mesage = '''
--------------------
Name : %s
AGE : %s
Work : %s
''' % (name,age,work)
print (mesage)
八 常用模块 ( getpass os tab)模块
乌版图python3 用
import getpass
name = input("what your name:")
password = getpass.getpass("password")
print(name,password)
在 python 环境下
import os
os.system("df -h")
a=os.popen("df -h").read()
print(a)#结果打印出来
os.mkdir("you Dir") 创建目录
os.system("ls z*")
import tab
1 #!/usr/bin/env python
2 # python startup file
3 import sys
4 import readline
5 import rlcompleter
6 import atexit
7 import os
8 # tab completion
9 readline.parse_and_bind('tab: complete')
10 # history file
11 histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
12 try:
13 readline.read_history_file(histfile)
14 except IOError:
15 pass
16 atexit.register(readline.write_history_file, histfile)
17 del os, histfile, readline, rlcompleter 九 if 语句 else
user = 'alex'
passwd= 'alex3714'
username = input("username:")
password = input("password:")
if user == username and passwd == password:
print("Welcome login")
else:
print("Invalid username or password..")
if user == username and passwd == password:
print("Welcome login")
else:
print("Invalid username or password..")
if else 优化
user = 'alex'
passwd= 'alex3714'
username = input("username:")
password = input("password:")
if user == username and passwd == password:
print("Welcome login")
else:
print("Invalid username or password..")
十 for i in range(10):
print (i)
缩进 TAB
往回缩 shift tab
age =31
con = 0
for i in range(10):
if con <3:
guss = int(input("how old:"))
if guss == age:
print("ok")
break
elif guss <age:
print("smale")
else:
print("big")
else:
wan = input("plase hai wan ma?")
if wan == 'y':
con = 0
contiue# 不往下走
else:
print("no")
break
con=con+1
python1day的更多相关文章
- Python-1-Day
C = float(input("Enter a degree in Celsius:"))F = (9/5) * C + 32print("{0} Celsius is ...
随机推荐
- CSS中的display属性
CSS中的display属性 display:block是可以把非块级元素强制转换为块级元素显示,如内嵌元素span,原来不支持设置宽高,宽度是由内容撑开的,几个span元素是在同一行内的,如果给sp ...
- Android 多线程处理之多线程用法大集合
handler.post(r)其实这样并不会新起线程,只是执行的runnable里的run()方法,却没有执行start()方法,所以runnable走的还是UI线程. 1.如果像这样,是可以操作ui ...
- 浅谈五大Python Web框架
转载:http://feilong.me/2011/01/talk-about-Python-web-framework 说到Web Framework,Ruby的世界Rails一统江湖,而Pytho ...
- OC 相关
1.OC runtime的理解[转载] http://www.csdn.net/article/2015-07-06/2825133-objective-c-runtime/1
- 命名空间System.Threading命名空间的同步锁 Monitor类
官方备注: Monitor类通过向单个线程授予对象所来控制对对象的访问.对象所提供限制访问代码块的能力.当一个线程拥有对象的锁时,其他任何线程都不能获取该锁.还可以使用Monitor来确保不会允许其他 ...
- Chapter 4: Troubleshoot and debug web applications
Prevent and troubleshoot runtime issues Troubleshooting performance, security and errors using perfo ...
- (转) Deep Learning Research Review Week 2: Reinforcement Learning
Deep Learning Research Review Week 2: Reinforcement Learning 转载自: https://adeshpande3.github.io/ad ...
- 别再为了this发愁了------JS中的this机制
别再为了this发愁了------JS中的this机制 题记:JavaScript中有很多令人困惑的地方,或者叫做机制.但是,就是这些东西让JavaScript显得那么美好而与众不同.比方说函数也是对 ...
- ruby : nil?, empty? and blank?的选择
article = nil article.nil? # => true empty? checks if an element - like a string or an array f.e. ...
- 如何在 Delphi 中静态链接 SQLite
搞了我几个小时,终于成功在 Delphi 中静态链接了 SQLite (v3.5.4),下一步就是研究加密了,呵呵中间其实遇到很多问题,今天累了,就不说了,改天补上 下载测试工程 下面说说方法 1.当 ...