博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python之路
阅读量:4624 次
发布时间:2019-06-09

本文共 2878 字,大约阅读时间需要 9 分钟。

主题是python的相关内容。学python主要是因为感觉国内现在Python缺口比较大,给的薪资较高。

自己的基础不是很牢,权当是从头学pyhton吧。

 

正文开始

DAY(一)

第一个程序

字符串拼接-StringContenation

# encoding: utf-8

'''
@author: ccq
@file: StringConcatenation.py
@time: 2019/5/19 10:09
'''
# 字符串拼接及格式化输出
name = 'ccq'
job = 'college student'
age = '21'
# format的第一种输出格式
info1 = "This is info1. Hi,i'am {0}. my age is {1} and i am a {2}.".format(name, job, age)
print(info1)
# format的第二种输出格式
info2 = "This is info2. Hi,i'am {_name}. my age is {_job} and i am a {_age}.".format(_name=name, _job=job, _age=age)
print(info2)
# 格式化输出
hobby = input("hobby:")
info3 = '''
------------- info of {_name} -------------
job:{_job}
age:{_age}
hobby:{_hobby}
'''.format(_name=name, _job=job, _age=age, _hobby=hobby)
print(info3)
#pyhton的输出格式还有很多,比如%s的格式,但是感觉format的格式更好用也更清晰,所以这里主要记录了format格式

==========================================分割线======================================

第二个程序

明文密文-Ciphertext

# encoding: utf-8

'''
@author: ccq
@file: Ciphertext.py
@time: 2019/5/19 10:32
'''
# 明文和密文
import getpass
# 明文
username1=input('username:')
password1=input('password:')
print(username1+'\n'+password1)
# 密文 python中可以用,pycharm里不可以用
username2=input('username:')
password2=getpass.getpass('password:')
print(username2+'\n'+password2)
#权当了解,import 模块

==========================================分割线======================================

第三个程序

ifelse循环-ifelse_password

# encoding: utf-8

'''
@author: ccq
@file: Ifelse_password.py
@time: 2019/5/19 10:41
'''
# if else循环控制流判断用户名密码
username1 = 'ccq'
password1 = '123'
username2 = input('username:')
password2 = input('password:')
if username1 == username2:
if password1==password2:
print('Welcome user {name} to use the computer'.format(name=username1))
else:
print("Invalid password , please input password again!")
else:
print("Invalid username ,please input username again!")
#python对代码格式要求很严,个人觉得这有优势也有劣势。优势在于  对程序员编码要求很严,这样对编码规范很有好处,同时也便于阅读。劣势在于  代码较长的时候没有{}易于判断。

==========================================分割线======================================

第四个程序

For循环-forloop

# encoding: utf-8

'''
@author: ccq
@file: ForLoop.py
@time: 2019/5/19 15:10
'''
# For循环
for i in range(2,10,2):
print("loop:",i)
#pyhton的for循环和其他语言的很不相同,习惯起来有些难度

==========================================分割线======================================

第五个程序

while循环-while_guessage

# encoding: utf-8

'''
@author: ccq
@file: While_guessage.py
@time: 2019/5/19 11:04
'''
# 使用while循环猜年龄大小
trueage = 21
count=0
while count<3:
age = int(input("please guess the age:"))
if age == trueage:
print("congratulations! you already guessed the true age")
break
elif age > trueage:
print("too old for me!think yonger!")
else:
print("too yong for me!think older!")
count += 1
else:
print("you are too foolish to guess my age! fuck off!")
#pyhthon的while循环和java比较相同。但是pyhton的else语句挺强大。目前看来是个很好用的东西。比如第五个程序的最后两行。
---------------------

转载于:https://www.cnblogs.com/hyhy904/p/11211001.html

你可能感兴趣的文章
django里面DTL使用for循环时,获取当前循环次数使用{{forloop.counter}}
查看>>
Java基础——Java集合(二)
查看>>
详解如何让Android UI设计性能更高效
查看>>
使用KNN算法对鸢尾花数据集进行分类处理
查看>>
java排序-按照实体的多种属性值进行排序(ComparableComparator/ComparatorChain)
查看>>
Django模板语言
查看>>
Django路由系统
查看>>
提高生产性工具(四) - XML数据库的尝试
查看>>
ural 1005 Stone Pile DP
查看>>
day15—jQuery UI之widgets插件
查看>>
使用ssh和putty操控远程的linux server
查看>>
BZOJ1499: [NOI2005]瑰丽华尔兹
查看>>
过滤器
查看>>
Redis是什么?
查看>>
JavaScript 学习总结
查看>>
iOS开发——UI进阶篇(十)导航控制器、微博详情页、控制器的View的生命周期...
查看>>
多线程(四)线程生命周期和线程池
查看>>
fetch的用法
查看>>
2017.08.11【NOIP提高组】模拟赛B组 小X的佛光
查看>>
【转】[精华] 跟我一起写 Makefile
查看>>