-
s = '这是一句中英文混合的Python字符串:Hello World!'
print(s)查看全部 -
template2 = 'Hello {2}, Hello {3}, Hello {1}, Hello {0}.'
result2 = template2.format('World', 'China', 'Beijing', 'imooc')
print(result2)查看全部 -
运行Python程序有两种方式,第一种是直接通过命令行编写代码运行,第二种是通过编辑器编写代码运行。
查看全部 -
#1
template='life is short,you need {}'
python=python
print(template.format(python))
查看全部 -
a="hello "
b="world"
print(a,b)查看全部 -
for item in L:
if item in S:
S.remove(item)
else:
S.add(item)查看全部 -
name_set=set(names)
查看全部 -
value可以是任意类型的元素,可以是list、tuple等,假如Mimi近两次成绩分别是72,73,Dodo近两次的成绩分别是88,90,则可以使用赋值语句往dict中添加list元素。
查看全部 -
布尔运算只有两种结果 True,False 用and,or,not运算 对应与,或,非运算,真(True),假(False)
与运算:两真为真,一假为假 只有两个布尔值都为 True 时,计算结果才为 True。两真为真,一假为假
True and True # ==> True
True and False # ==> False
False and True # ==> False
False and False # ==> False或运算:一真为真,两假为假 只要有一个布尔值为 True,计算结果就是 True。两假为假,一真为真
True or True # ==> True
True or False # ==> True
False or True # ==> True
False or False # ==> False非运算:真对应假,假对应真 把True变为False,或者把False变为True 非真即假,非假即真
not True # ==> False
not False # ==> True
需要注意的是,not计算的优先级是高于and和or的。查看全部 -
四则运算 浮点数可以表达整数的结果,但是整数不能表达浮点数的结果。
取模运算 使用百分号%表示取模。使用取模运算,可以判断一个数是否为偶数,当一个数对2取模结果为0时,则这个数为偶数,否则为奇数。
print(3 % 2) # ==> 1 因此3为奇数
print(33 % 2) # ==> 1 因此33为奇数
print(100 % 2) # ==> 0 因此100为偶数地板除 得到的结果会忽略纯小数的部分,得到整数的部分,地板除使用//进行。
10//4 # ==> 2
10//2.5 # ==> 4.0
10//3 # ==> 3小数点位数 round()函数 round(变量,位数)
round的调用方式,使用两个参数,第一个是需要保留小数点位数的数值,第二个是保留的位数。
查看全部 -
# Enter a code
str=r'''"To be, or not to be": that is the question.'''+'\n'+r'''Whether it's nobler in the mind to suffer.''';
print(str);
查看全部 -
L = ['Alice', 66, 'Bob', True, 'False', 100]
n = 0
for item in L :
n = n + 1
if n%2 == 0 :
continue
print(item)
查看全部 -
# Enter a code
L = ['Chinese', 92, 'Math', 75, 'English', 99]
print(L)
查看全部 -
cmp()函数,可以比较两个数的大小,
查看全部 -
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for i in s1:
for n in s2:
for m in s3:
print(i + n + m)查看全部
举报