python学习之路(第一天)
2018-03-26 11:24
204 查看
研究僧在读python小白,有些许c语言基础,在此附上自己学习python之路,除了部分精要之处详解,其余部分楼主只附上代码,留作回顾!
字符串要点
name = input("name:") #raw_input 2.x input 3.x #input 2.x = age = int(input("age:") ) #integer print(type(age) , type( str(age) )) job = input("job:") salary = input("salary:") #第一种,%s占位,% (name,name,age,job,salary)对应补位 info = ''' -------- info of %s ------ Name:%s Age:%d Job:%s Salary:%s ''' % (name,name,age,job,salary) #利用.format info2 = ''' -------- info of {_name} ----- Name:{_name} Age:{_age} Job:{_job} Salary:{_salary} '''.format(_name=name, _age=age, _job=job, _salary=salary) #类似2 info3 = ''' -------- info of {0} ----- Name:{0} Age:{1} Job:{2} Salary:{3} '''.format(name,age,job,salary) print(info) #print(info2) #print(info3)
循环要点(while, break,continue, if ,elif, for)
age = 56 count = 0 while count <3:#运行三次 guess_age = int(input("guess age:") ) if guess_age == age : print("yes, you got it. ") break #猜对了就跳出循环 elif guess_age > age: #c语言是 else if print("think smaller...") else: print("think bigger!") count +=1 if count == 3: countine_confirm = input("do you want to keep guessing..?") if countine_confirm != 'n':#输入n结束程序,否则继续执行 count =0
age = 56 child=10 count=0 while count<2: for i in range(3): #加入for guess_age = int(input("guess age:") ) if guess_age == age : print("yes, you got it. ") break elif guess_age > age: print("think smaller...") elif guess_age< child: print("i'm not a chlid, you idiot!") else: continue count+=1; if count==2: guess=input("You serious? give it up!") if guess !='ok': count=0 else: print("you have tried too many times..fuck off")判断用户
import getpass _username = 'shiwei' _password = 'abc123' username = input("username:") password = getpass.getpass(" Input the password:") #password = input("password:") #if _password == password and _username=username: if _password == password: print("Welcome user {name} login...".format(name=username)) else: print("Invalid username or password!") #pycharm 不支持getpass, 可以将第5句和第8句换成 6-7句来判断。未完待续。。。
阅读更多
相关文章推荐
- python学习之路-第一天-接触python
- Python 机器(算法)学习-----第一天
- Python小白学习之路(六)—— 【元祖】【元祖相关功能】
- Python学习之路--Flask+MongoDB搭建Restful Server
- python学习之路之案例2---计算器
- Python学习之路:一些BIF+魔法方法+模块
- 我的Python学习之路九:条件控制与循环语句
- 我的python学习之路-10
- python学习之路-第八天-文件IO、储存器模块
- Python小白学习之路(十五)—【map()函数】【filter()函数】【reduce()函数】
- 学习第一天(python)
- Python小白学习之路(十六)—【内置函数一】
- python学习之路四--if语句
- python学习之路--threading Lock对象
- python学习之路
- 我的python学习之路-04
- Python学习之路--初始
- Python学习之路---Python元组
- python 学习之路(字符串的常用操作)
- python学习之路 八 :面向对象编程基础