menu 喵雨の小屋
search assignment self_improvement

PYTHON学习实例1

MeowRain
MeowRain 2020年11月05日 阅读:193

问题实例

# 问题实例
name = input('What is your name ?')
print('hello,my friends' +  ' ' + name)
fav_color = input('what is your favourite color')
print(name + 'likes ' + fav_color)

年龄计算实例1

age = input('你的年龄:')
print(type(age)) #可用type查看类型
birth_year = 2020 - int(age)
print(type(birth_year))
print(birth_year)

年龄计算实例2

birth_time = input('你的出生年')
nage = 2020 - int(birth_time)
print(nage)

引号的使用

course = "MGSY's Blog is very good!" # 使用单引号和双引号
coursetwo = 'MGSY "BLOG" is very good!' 
#三引号使用
quote = '''
HI john,

thanks for your reply

Support team

'''
print(quote)
print(course)
print(coursetwo)

方括号的使用

name = 'MGSY "bLOG " is very good'
print(name[0]) #第一个字符
print(name[1])#第二个字符
print(name[2])#第三个字符
print(name[-1])#从右面开始第一个字符
print(name[0:3])#从左起到第三个字符
分类: 笔记
标签: python
目录