Python 的布尔类型
flag = True and False
print('flag:', flag) # flag: False
flag = True or False
print('flag:', flag) # flag: True
flag = not False
print('flag:', flag) # flag: True
Python 的字符串 format
template = 'Hello {}'
text = 'world'
result = template.format(text)
print('r:', result) # r: Hello world
Python 的流程控制
score = 78
if(score < 60):
print('faile!')
elif(score < 80):
print('good!')
else:
print('nice!')
Python 的 for 循环
text= 'python'
for char in text:
print(char)
Python 的容器
list:
students = ['wang', 'li', 'zhang', 'liu']
# 获取元素
print(students[2], students[-2]) # zhang zhang
# 删除元素
s = students.pop()
print(s, students) # liu ['wang', 'li', 'zhang']
# 添加元素
students.append('xi')
print(students) # ['wang', 'li', 'zhang', 'xi']
dict:
scores = {
'wang': 80,
'liu': 78,
'li': 100
}
print(scores['li']) # 100
scores.pop('liu')
print(scores) # {'wang': 80, 'li': 100}
函数
函数与可变参数:
def func(*args):
print('args length = {}, args = {}'.format(len(args), args))
func('zhang', 'peng') # args length = 2, args = ('zhang', 'peng')
可变关键字:
def func(**kwargs):
print(('name: {}, age: {}').format(kwargs.get('name'), kwargs.get('age')))
func(name = 'wang', age = 17) # name: wang, age: 17
标签:wang,zhang,Python,基础,students,flag,print From: https://www.cnblogs.com/new-bee-2023/p/17488991.html