发布时间:2019-07-19 09:50:45编辑:auto阅读(1577)
为了坚持而坚持(这话说了自己不信)
作为一个不懂编程的桌面,在技术的路上越走越远,严重到了找工作都很难的阶段,很心酸。。。作为一个干啥啥不行,吃啥啥有够,韩剧看不够,年纪又不小的我来说,在进步很难,不知路又走到哪就跑偏了,为了找到好工作而学习,至少希望可以升级做个小运维也是很满足的。
没有野心的人,想在现在生存,比有野心的人还要艰难。知足没有常乐,知足只是在后退而已!
网上学习python 对于我这样没组织没纪律的人,貌似起不到神马作用,忽略我没钱报培训班,还是硬着头皮,希望靠着大神的视频让我有所进步吧!
视频中python 入门第一篇结束后,要求写博客,我是假装听老师的话,然后过来自我安慰。
没啥语言功底,数学一般逻辑性不强,字迹潦潦草草,写出的东西也只有自己能看。
python01
小白入门的第一天
了解python,
神马是python,是蟒蛇。
为啥python要用.py 结尾,为了让其他人知道你写的这是个python 脚本,老师推荐最好使用pycharm脚本编辑器,下了个试用版,免费使用30天。
python 版本 3.6 (最好学习使用3.0 版本,2.0 过时了)
字符编码
ASCII 编码
定义变量 name = "Hello World"
print (name)
3.用户输入(input)和格式化输出
例:用户输入(input)
username = input("type your username:")
print(username)
格式化输出
a,例:字符串拼接(''' + ''')
username = input ("username is :")
age = input("age is :")
job = input("job is:")
salary=input("salary is:")
info1='''
------info1 is ''' + username '''-----------
username is : '''+ username '''
age is : ''' +age '''
job is : '''+job '''
salary is : ''' + salary
print (info1)
b, 字符串拼接(''' %s ''') ,s= string 字符串
username = input ("username is :")
age = input("age is :")
job = input("job is:")
salary=input("salary is:")
info2='''
------info2 is %s-----------
username is : %s
age is : %s
job is : %s
salary is : %s
'''%(username,username,age,job,salary)
print (info2)
c, 字符串拼接(''' %s ''') s= string %d=整数 int=强制为数字?
username = input ("username is :")
age = int(input("age is :"))
job = input("job is:")
salary=input("salary is:")
info3='''
------info3 is %s-----------
username is : %s
age is : %d
job is : %s
salary is : %s
'''%(username,username,age,job,salary)
print (info3)
d, 字符串拼接(使用排序.format)
username = input ("username is :")
age = input("age is :")
job = input("job is:")
salary=input("salary is:")
info4='''
------info4 is {0}-----------
username is : {0}
age is : {1}
job is : {2}
salary is : {3}
'''.format(username,age,job,salary)
print (info4)
e, 字符串拼接(.format)
username = input ("username is :")
age = input("age is :")
job = input("job is:")
salary=input("salary is:")
info5='''
------info5 is {_username}-----------
username is : {_username}
age is : {_age}
job is : {_job}
salary is : {_salary}
'''.format(username=_username,
age=_age,
job=_job,
salary=_salary)
print (info5)
以上的输出(print)结果是:
**/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 "/Users/a1/PycharmProjects/untitled3/day1/user input.py"
username is :alex
your job is:IT
your age is:23
salary is :232323
4.密码加密
例:
username = input("username:")
password = getpass.getpass("password:")
print (username,password)
5.if 条件判断语句()
例:
oldboy_age=55
age = input("guess oldboy age is :")
if oldboy_age == age
print("yes,you got it")
else
print("wrong ansser")
加上条件:使用户最多可以猜错三次条件
或是while 加条件语句如(while count < 3 )
定义计数器 count = 0, count += 1 每次循环+1
跳出循环break
例:
age= 55
count = 0
while True:
if count == 3:
break
guess = int(input("guess age :"))
if guess == age:
print("yes,you got it.")
elif guess < age:
print("think older.")
else:
print ("think smaler")
count += 1
执行的结果为:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 "/Users/a1/PycharmProjects/untitled3/day1/whiel True 循环.py"
guess age :23
think older.
guess age :23
think older.
guess age :23
think older.
Process finished with exit code 0
对以上的代码做优化
例:
age = 55
count = 0
while count < 3:
guess = int(input("guess age: "))
if age == guess:
print ("yes ,you got it")
elif age < guess:
print ("think older")
else:
print ("think smaller")
count += 1
** # if count == 3:
else:
print("you have try too many times.")
输出结果是:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 "/Users/a1/PycharmProjects/untitled3/day1/whiel True 循环.py"
guess age: 34
think smaller
guess age: 35
think smaller
guess age: 78
think older
you have try too many times.
Process finished with exit code 0
6.continue #跳出本次循环,执行下一次循环
while True:
for i in range(3):
user = int(input("guess age:"))
if user == age:
print("1")
elif user > age:
print(">")
elif user < age:
print("<")
con = input("do you want con?")
if con == 'c':
continue
else:
break
age_of_oldboy = 55
count = 0
while count < 3:
age = int(input("please input age of oldboy:"))
if age_of_oldboy == age:
print("yes ,you got it!")
break
elif age_of_oldboy < age:
print("think smaller")
else:
print("think older")
count += 1
if count == 3:
continue_confirm = input("do you want to keep guessing..?")
if continue_confirm != 'n':
count = 0
# != 不等于
上一篇: python 集合、函数
下一篇: python -模块与包
47483
45786
36783
34310
28955
25589
24436
19606
19096
17626
5458°
6041°
5557°
5632°
6558°
5370°
5370°
5877°
5850°
7163°