标签:
#!/usr/bin/env python 声明解释其类型 # -*- coding:utf-8 -*- 国际编码支持中文 # Author:QL 作者 name = ‘QL‘ #变量名要让人看懂不能起无意义名称,方便日后查看 name2 = name # name2=name 其实是直接赋值name2="QL" print(name,name2) #3.5版本打印加括号 name = ‘lanlan‘ # name重新赋值 那么name2=? print(name,name2) #(‘lanlan‘,‘QL‘)
#!/usr/bin/env python name = input("input your name:") age = input("input your age:") job = input("input your job:") msg =‘‘‘ Information of user %s: ----------------------- Name: %s Age : %s # %d 整数%f 浮点数%s字符 Job : %s ---------end---------- ‘‘‘ %(name,name,age,job) print(msg)
#!/usr/bin/env python user = ‘QL‘ passwd = ‘123‘ #用引号引起来代表123为字符串,如果不用引号的数字, #就是整数那么password应用int声明是数字 password = int(input()) username = input("username:") password = input("password:") if username == user and password == passwd print("Welcome login...") else: print("invalid username or password...")
#!/usr/bin/env python import getpass username = input("username:") password = getpass.getpass("password") #密文输入密码 print(username,password) import os os.system(‘df‘) #使用shell命令 os.mkdir(‘yourdir‘) cdm_res = os.popen(‘df -h‘).read() #命令输出结果赋值给一个变量 import sys print(sys.path) #查看路径 如果自己写的模块没在显示的路径下就找不到自己写的模块需要添加#‘/usr/lib/python2.7/dist-packages‘ 自己写的模块
guess age.py
#!/usr/bin/env python age = 22 counter = 0 for i in range(10): if counter <3: guess_num = int(input("input your guess num:")) if guess_num == age: print("You are right!") break #不往后走了,跳出整个loop elif guess_num >age: print("Think smaller!") else: print("Think bigger") else: continue_confirm = input("Do you want to continue ?:") if continue_confirm =‘y‘: counter = 0 continue #跳出本次循环 else: break #跳出整个for循环 counter +=1
标签:
原文地址:http://www.cnblogs.com/QL8533/p/5482206.html