-
目前CPU硬件提升,运行速度慢在平常情况下,就不是问题。
查看全部 -
# 编写一个函数,它接受关键字参数names,gender,age三个list,分别包含同学的名字、性别和年龄,请分别把每个同学的名字、性别和年龄打印出来
def f1( **kwargs ):
L_names = kwargs.get('name')
L_gender = kwargs.get('gender')
L_age = kwargs.get('age')
i = 0
while i < len(L_names) :
temp1 = 'Name is {0},gender is {1},age is {2}'
print(temp1.format(L_names[i],L_gender[i],L_age[i] ))
i = i +1
f1(name = ['Ali','Bok','Pse'], gender = ['Male','Male','Fmale'],age = [10,37,26])
查看全部 -
输出结果
hello python
hello world查看全部 -
a="python"
print('hello,', a or 'world')
b=''
print('hello,', b or 'world')
查看全部 -
Python之if-else语句
score = 59
if score < 60:
print('抱歉,考试不及格')
else:
print('恭喜你,考试及格')查看全部 -
L=['Alice', 66, 'Bob', True, 'False', 100]
index=0
for item in L:
if index%2==0:
print(L[index])
index+=1查看全部 -
L = ['Chinese:', 92, 'Math:', 75 ,'English:', 99]
print(L)查看全部 -
Python之if语句
score = 59
if score < 60:
print('抱歉,考试不及格')
# ==> 抱歉,考试不及格可以看到print('抱歉,考试不及格')这行代码明显比上一行代码缩进了,这是因为这行代码是if判断的一个子分支,因此需要缩进,在Python规范中,一般使用4个空格作为缩进
在if语句的最后,有一个冒号:,这是条件分支判断的格式,在最后加入冒号:,表示接下来是分支代码块
查看全部 -
Python的字符串切片
按照位置取字符串的方式使用中括号[ ]访问
s = 'ABC'
a = s[0] # 第一个
b = s[1] # 第二个
c = s[2] # 第三个
print(a) # ==> A
print(b) # ==> B
print(c) # ==> C查看全部 -
age1=18
if age1>=18:
print('adult')
else:
print('teenager')
age2=17
if age2>=18:
print('adult')
else:
print('teenager')查看全部 -
ddq_age=19
if ddq_age>=19:
print('dongdongqiang is adult,his age is '+str(ddq_age))查看全部 -
template='life is {1},you need {0}'
result=template.format('python','short')
print(result)
template1='life is {s},you need {p}'
ss='short'
pp='python'
result1=template1.format(s=ss,p=pp)
print(result1)查看全部 -
print(r''''\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.' ''')
raw字符的作用是让转义字符 \ 无效查看全部 -
字符串format
方式1:template = 'Hello {}'
world = 'World'
result = template.format(world)
print(result) # ==> Hello World方式2:
template = 'Hello {3}, Hello {2}, Hello {1}, Hello {0}.'
result = template.format('World', 'China', 'Beijing', 'imooc')
print(result) # ==> Hello imooc, Hello Beijing, Hello China, Hello World.方式3:
template = 'Hello {w}, Hello {c}, Hello {b}, Hello {i}.'
world = 'World'
china = 'China'
beijing = 'Beijing'
imooc = 'imooc'
result = template.format(w = world, c = china, b = beijing, i = imooc)
print(result) # ==> Hello World, Hello China, Hello Beijing, Hello imooc.查看全部 -
多行字符串转义
r'''字符串1
字符串2
字符串3'''
查看全部
举报